Skip to content

Commit df90076

Browse files
committed
Add minimum and maximum to Data.Semigroup.Foldable
These are handy because, unlike `Data.Foldable` they don't return a `Maybe`.
1 parent a1d31b5 commit df90076

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
],
1919
"dependencies": {
2020
"purescript-bifunctors": "^3.0.0",
21-
"purescript-maybe": "^3.0.0"
21+
"purescript-maybe": "^3.0.0",
22+
"purescript-orders": "^3.0.0"
2223
},
2324
"devDependencies": {
2425
"purescript-assert": "^3.0.0",

src/Data/Semigroup/Foldable.purs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import Prelude
1313
import Data.Foldable (class Foldable)
1414
import Data.Monoid.Dual (Dual(..))
1515
import Data.Monoid.Multiplicative (Multiplicative(..))
16+
import Data.Newtype (ala)
17+
import Data.Ord.Max (Max(..))
18+
import Data.Ord.Min (Min(..))
1619

1720
-- | `Foldable1` represents data structures with a minimum of one element that can be _folded_.
1821
-- |
@@ -71,3 +74,9 @@ for1_ = flip traverse1_
7174
-- | given by the `Foldable1` instance, ignoring the final result.
7275
sequence1_ :: forall t f a. Foldable1 t => Apply f => t (f a) -> f Unit
7376
sequence1_ = traverse1_ id
77+
78+
maximum :: forall f a. Ord a => Foldable1 f => f a -> a
79+
maximum = ala Max foldMap1
80+
81+
minimum :: forall f a. Ord a => Foldable1 f => f a -> a
82+
minimum = ala Min foldMap1

0 commit comments

Comments
 (0)