@@ -9,6 +9,8 @@ module Data.Semigroup.Foldable
9
9
, sequence1_
10
10
, foldr1Default
11
11
, foldl1Default
12
+ , foldMap1DefaultR
13
+ , foldMap1DefaultL
12
14
, foldMap1Default
13
15
, intercalate
14
16
, intercalateMap
@@ -26,6 +28,7 @@ import Data.Monoid.Multiplicative (Multiplicative(..))
26
28
import Data.Newtype (ala , alaF )
27
29
import Data.Ord.Max (Max (..))
28
30
import Data.Ord.Min (Min (..))
31
+ import Prim.TypeError (class Warn , Text )
29
32
30
33
-- | `Foldable1` represents data structures with a minimum of one element that can be _folded_.
31
34
-- |
@@ -37,7 +40,8 @@ import Data.Ord.Min (Min(..))
37
40
-- |
38
41
-- | - `foldr1Default`
39
42
-- | - `foldl1Default`
40
- -- | - `foldMap1Default`
43
+ -- | - `foldMap1DefaultR`
44
+ -- | - `foldMap1DefaultL`
41
45
-- |
42
46
-- | Note: some combinations of the default implementations are unsafe to
43
47
-- | use together - causing a non-terminating mutually recursive cycle.
@@ -48,22 +52,36 @@ class Foldable t <= Foldable1 t where
48
52
foldMap1 :: forall a m . Semigroup m => (a -> m ) -> t a -> m
49
53
50
54
-- | 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`.
51
58
foldr1Default :: forall t a . Foldable1 t => (a -> a -> a ) -> t a -> a
52
59
foldr1Default = flip (runFoldRight1 <<< foldMap1 mkFoldRight1)
53
60
54
61
-- | A default implementation of `foldl1` using `foldMap1`.
55
62
-- |
56
63
-- | Note: when defining a `Foldable1` instance, this function is unsafe to use
57
- -- | in combination with `foldMap1Default `.
64
+ -- | in combination with `foldMap1DefaultL `.
58
65
foldl1Default :: forall t a . Foldable1 t => (a -> a -> a ) -> t a -> a
59
66
foldl1Default = flip (runFoldRight1 <<< alaF Dual foldMap1 mkFoldRight1) <<< flip
60
67
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
+
61
75
-- | A default implementation of `foldMap1` using `foldl1`.
62
76
-- |
63
77
-- | Note: when defining a `Foldable1` instance, this function is unsafe to use
64
78
-- | 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
67
85
68
86
instance foldableDual :: Foldable1 Dual where
69
87
foldr1 _ (Dual x) = x
0 commit comments