Skip to content

Commit dc70cf3

Browse files
committed
Deprecate and split foldMap1Default into foldMap1DefaultL and foldMap1DefaultR
1 parent daa432b commit dc70cf3

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/Data/Semigroup/Foldable.purs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ module Data.Semigroup.Foldable
99
, sequence1_
1010
, foldr1Default
1111
, foldl1Default
12+
, foldMap1DefaultR
13+
, foldMap1DefaultL
1214
, foldMap1Default
1315
, intercalate
1416
, intercalateMap
@@ -26,6 +28,7 @@ import Data.Monoid.Multiplicative (Multiplicative(..))
2628
import Data.Newtype (ala, alaF)
2729
import Data.Ord.Max (Max(..))
2830
import Data.Ord.Min (Min(..))
31+
import Prim.TypeError (class Warn, Text)
2932

3033
-- | `Foldable1` represents data structures with a minimum of one element that can be _folded_.
3134
-- |
@@ -37,7 +40,8 @@ import Data.Ord.Min (Min(..))
3740
-- |
3841
-- | - `foldr1Default`
3942
-- | - `foldl1Default`
40-
-- | - `foldMap1Default`
43+
-- | - `foldMap1DefaultR`
44+
-- | - `foldMap1DefaultL`
4145
-- |
4246
-- | Note: some combinations of the default implementations are unsafe to
4347
-- | use together - causing a non-terminating mutually recursive cycle.
@@ -48,22 +52,36 @@ class Foldable t <= Foldable1 t where
4852
foldMap1 :: forall a m. Semigroup m => (a -> m) -> t a -> m
4953

5054
-- | A default implementation of `foldr1` using `foldMap1`.
55+
-- |
56+
-- | Note: when defining a `Foldable1` instance, this function is unsafe to use
57+
-- | in combination with `foldMap1DefaultR`.
5158
foldr1Default :: forall t a. Foldable1 t => (a -> a -> a) -> t a -> a
5259
foldr1Default = flip (runFoldRight1 <<< foldMap1 mkFoldRight1)
5360

5461
-- | A default implementation of `foldl1` using `foldMap1`.
5562
-- |
5663
-- | Note: when defining a `Foldable1` instance, this function is unsafe to use
57-
-- | in combination with `foldMap1Default`.
64+
-- | in combination with `foldMap1DefaultL`.
5865
foldl1Default :: forall t a. Foldable1 t => (a -> a -> a) -> t a -> a
5966
foldl1Default = flip (runFoldRight1 <<< alaF Dual foldMap1 mkFoldRight1) <<< flip
6067

68+
-- | A default implementation of `foldMap1` using `foldr1`.
69+
-- |
70+
-- | Note: when defining a `Foldable1` instance, this function is unsafe to use
71+
-- | in combination with `foldr1Default`.
72+
foldMap1DefaultR :: forall t m a. Foldable1 t => Functor t => Semigroup m => (a -> m) -> t a -> m
73+
foldMap1DefaultR f = map f >>> foldr1 (<>)
74+
6175
-- | A default implementation of `foldMap1` using `foldl1`.
6276
-- |
6377
-- | Note: when defining a `Foldable1` instance, this function is unsafe to use
6478
-- | in combination with `foldl1Default`.
65-
foldMap1Default :: forall t m a. Foldable1 t => Functor t => Semigroup m => (a -> m) -> t a -> m
66-
foldMap1Default f = map f >>> foldl1 (<>)
79+
foldMap1DefaultL :: forall t m a. Foldable1 t => Functor t => Semigroup m => (a -> m) -> t a -> m
80+
foldMap1DefaultL f = map f >>> foldl1 (<>)
81+
82+
-- | Deprecated previous name of `foldMap1DefaultL`.
83+
foldMap1Default :: forall t m a. Warn (Text "'foldMap1Default' is deprecated, use 'foldMap1DefaultL' instead") => Foldable1 t => Functor t => Semigroup m => (a -> m) -> t a -> m
84+
foldMap1Default f = foldMap1DefaultL
6785

6886
instance foldableDual :: Foldable1 Dual where
6987
foldr1 _ (Dual x) = x

0 commit comments

Comments
 (0)