andmap in Haskell?

Viewed 570

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?

2 Answers

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
Related