0

I have a code to find the length of a list that passes a certain criteria. For example, ispos x = x > 0. I need to create another function that uses that function and returns the list of items that are satisfied by that and also is satisfied by they are greater than 10. How do I go about this? Here is my code for counting the list:

count'filter :: (a -> Bool) -> [a] -> Int
count'filter p = length . filter p
chepner
  • 497,756
  • 71
  • 530
  • 681
  • 2
    This looks suspiciously similar to this question... https://stackoverflow.com/questions/69305667/how-do-i-get-the-length-of-my-list-in-haskell-after-creating-it which was down voted not long ago. – Fogmeister Sep 23 '21 at 21:08

1 Answers1

1

count'filter won't help you write the function you want. You appear to want to combine a predicate of (>= 10) to the predicate p, which you would simply do using &&:

newFunction :: Num a => (a -> Bool) -> [a] -> [a]
newFunction p = filter (\x -> p x && x >= 10)
chepner
  • 497,756
  • 71
  • 530
  • 681
  • Please update your question with a sample call to your new function and the expected result. What you are describing is not compatible with what `count'filter` currently does. – chepner Sep 23 '21 at 20:43
  • This doesn't compile without `Num a` constraint. – pedrofurla Sep 24 '21 at 04:13