Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 219175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:49:13+00:00 2026-05-11T18:49:13+00:00

The filter class of functions takes a condition (a -> Bool) and applies it

  • 0

The filter class of functions takes a condition (a -> Bool) and applies it when filtering.

What is the best way to use a filter on when you have multiple conditions?

Used the applicative function
liftA2 instead of liftM2 because I for some reason didn’t understand how liftM2 worked within pure code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:49:13+00:00Added an answer on May 11, 2026 at 6:49 pm

    The liftM2 combinator can be used in the Reader monad to do this in a ‘more functional’ way:

    import Control.Monad
    import Control.Monad.Reader
    
    -- ....
    
    filter (liftM2 (&&) odd (> 100)) [1..200]
    

    Note that the imports are important; Control.Monad.Reader provides the Monad (e ->) instance that makes this all work.

    The reason this works is the reader monad is just (e ->) for some environment e. Thus, a boolean predicate is a 0-ary monadic function returning bool in an environment corresponding to its argument. We can then use liftM2 to distribute the environment over two such predicates.

    Or, in simpler terms, liftM2 will act a bit like this when the types work out:

    liftM2 f g h a = f (g a) (h a)
    

    You can also define a new combinator if you want to be able to chain these easily, and/or don’t want to mess with liftM2:

    (.&&.) :: (a -> Bool) -> (a -> Bool) -> (a -> Bool)
    (.&&.) f g a = (f a) && (g a)
    -- or, in points-free style:
    (.&&.) = liftM2 (&&)    
    
    filter (odd .&&. (> 5) .&&. (< 20)) [1..100]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 236k
  • Answers 236k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I presume that your non-modal dialogs are WS_POPUP windows, right?… May 13, 2026 at 6:18 am
  • Editorial Team
    Editorial Team added an answer Unless the exported functions are something like a COM DLL… May 13, 2026 at 6:18 am
  • Editorial Team
    Editorial Team added an answer If the -devel port is not offered as a variant,… May 13, 2026 at 6:18 am

Related Questions

The filter class of functions takes a condition (a -> Bool) and applies it
I've got a class written in F# that I'm consuming in C#, that defines
I want get all of the Geom objects that are related to a certain
(A jQuery Question about filtering stuff on StackOverflow. I swear, it doesn't belong on
My question (which will follow after this, sorry about the long intro, the question

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.