Skip to content

Commit c41075b

Browse files
committed
Generalise and/or/any/all to BoundedLattice
1 parent 5749b88 commit c41075b

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

docs/Data.Foldable.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,31 +172,31 @@ combining adjacent elements using the specified separator.
172172
#### `and`
173173

174174
``` purescript
175-
and :: forall f. (Foldable f) => f Boolean -> Boolean
175+
and :: forall a f. (Foldable f, BoundedLattice a) => f a -> a
176176
```
177177

178178
Test whether all `Boolean` values in a data structure are `true`.
179179

180180
#### `or`
181181

182182
``` purescript
183-
or :: forall f. (Foldable f) => f Boolean -> Boolean
183+
or :: forall a f. (Foldable f, BoundedLattice a) => f a -> a
184184
```
185185

186186
Test whether any `Boolean` value in a data structure is `true`.
187187

188188
#### `any`
189189

190190
``` purescript
191-
any :: forall a f. (Foldable f) => (a -> Boolean) -> f a -> Boolean
191+
any :: forall a b f. (Foldable f, BoundedLattice b) => (a -> b) -> f a -> b
192192
```
193193

194194
Test whether a predicate holds for any element in a data structure.
195195

196196
#### `all`
197197

198198
``` purescript
199-
all :: forall a f. (Foldable f) => (a -> Boolean) -> f a -> Boolean
199+
all :: forall a b f. (Foldable f, BoundedLattice b) => (a -> b) -> f a -> b
200200
```
201201

202202
Test whether a predicate holds for all elements in a data structure.

src/Data/Foldable.purs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,19 +157,19 @@ intercalate sep xs = (foldl go { init: true, acc: mempty } xs).acc
157157
go { acc = acc } x = { init: false, acc: acc <> sep <> x }
158158

159159
-- | Test whether all `Boolean` values in a data structure are `true`.
160-
and :: forall f. (Foldable f) => f Boolean -> Boolean
161-
and = foldl (&&) true
160+
and :: forall a f. (Foldable f, BoundedLattice a) => f a -> a
161+
and = foldl (&&) top
162162

163163
-- | Test whether any `Boolean` value in a data structure is `true`.
164-
or :: forall f. (Foldable f) => f Boolean -> Boolean
165-
or = foldl (||) false
164+
or :: forall a f. (Foldable f, BoundedLattice a) => f a -> a
165+
or = foldl (||) bottom
166166

167167
-- | Test whether a predicate holds for any element in a data structure.
168-
any :: forall a f. (Foldable f) => (a -> Boolean) -> f a -> Boolean
168+
any :: forall a b f. (Foldable f, BoundedLattice b) => (a -> b) -> f a -> b
169169
any p = or <<< foldMap (\x -> [p x])
170170

171171
-- | Test whether a predicate holds for all elements in a data structure.
172-
all :: forall a f. (Foldable f) => (a -> Boolean) -> f a -> Boolean
172+
all :: forall a b f. (Foldable f, BoundedLattice b) => (a -> b) -> f a -> b
173173
all p = and <<< foldMap (\x -> [p x])
174174

175175
-- | Find the sum of the numeric values in a data structure.

0 commit comments

Comments
 (0)