@@ -14,27 +14,44 @@ class Foldable (t : Type -> Type) where
14foldl : Foldable t => (acc -> elt -> acc) -> acc -> t elt -> acc
14foldl : Foldable t => (acc -> elt -> acc) -> acc -> t elt -> acc
15foldl f z t = foldr (flip (.) . flip f) id t z
15foldl f z t = foldr (flip (.) . flip f) id t z
17+||| Combine each element of a structure into a monoid
17concat : (Foldable t, Monoid a) => t a -> a
18concat : (Foldable t, Monoid a) => t a -> a
18concat = foldr (<+>) neutral
19concat = foldr (<+>) neutral
21+||| Combine into a monoid the collective results of applying a function
22+||| to each element of a structure
20concatMap : (Foldable t, Monoid m) => (a -> m) -> t a -> m
23concatMap : (Foldable t, Monoid m) => (a -> m) -> t a -> m
21concatMap f = foldr ((<+>) . f) neutral
24concatMap f = foldr ((<+>) . f) neutral
26+||| The conjunction of all elements of a structure containing
27+||| lazy boolean values. `and` short-circuits from left to right,
28+||| evaluating until either an element is `False` or no elements remain.
23−and : Foldable t => t Bool -> Bool
29+and : Foldable t => t (Lazy Bool) -> Bool
24−and = foldr (&&) True
30+and = foldl (&&) True
32+||| The disjunction of all elements of a structure containing
33+||| lazy boolean values. `or` short-circuits from left to right, evaluating
34+||| either until an element is `True` or no elements remain.
26−or : Foldable t => t Bool -> Bool
35+or : Foldable t => t (Lazy Bool) -> Bool
27−or = foldr (||) False
36+or = foldl (||) False
38+||| The disjunction of the collective results of applying a
39+||| predicate to all elements of a structure. `any` short-circuits
40+||| from left to right.
29any : Foldable t => (a -> Bool) -> t a -> Bool
41any : Foldable t => (a -> Bool) -> t a -> Bool
30−any p = foldr ((||) . p) False
42+any p = foldl (\x => \y => x || p y) False
44+||| The disjunction of the collective results of applying a
45+||| predicate to all elements of a structure. `all` short-circuits
46+||| from left to right.
32all : Foldable t => (a -> Bool) -> t a -> Bool
47all : Foldable t => (a -> Bool) -> t a -> Bool
33−all p = foldr ((&&) . p) True
48+all p = foldl (\x => \y => x && p y) True
50+||| Add together all the elements of a structure
35sum : (Foldable t, Num a) => t a -> a
51sum : (Foldable t, Num a) => t a -> a
36sum = foldr (+) 0
52sum = foldr (+) 0
54+||| Multiply together all elements of a structure
38product : (Foldable t, Num a) => t a -> a
55product : (Foldable t, Num a) => t a -> a
39product = foldr (*) 1
56product = foldr (*) 1