In Racket, there is a really useful built in function andmap that lets see if a function evaluates to true on every element of a given list, as follows:
> (andmap number? (list 2 4 5))
#t
> (andmap number? (list 2 4 "foo"))
#f
Is there an equivalent of this in Haskell, or do you have to construct it yourself by using map and reduce?
You're looking for all:
> all (>0) [1, 2, 3]
True
> all (>0) [1, -2, 3]
False
you can use all for this purpose
e.g.
> all even [2,4]
True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With