From 60edb53839476e6d2857749adfdb29171cfa3d7c Mon Sep 17 00:00:00 2001 From: Cyril Sobierajewicz Date: Fri, 20 Nov 2020 00:05:59 +0100 Subject: [PATCH 1/2] Deprecate monomorphic foldl1 --- src/Data/NonEmpty.purs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Data/NonEmpty.purs b/src/Data/NonEmpty.purs index 9e5f75a..5e7df4a 100644 --- a/src/Data/NonEmpty.purs +++ b/src/Data/NonEmpty.purs @@ -23,11 +23,13 @@ import Data.FunctorWithIndex (class FunctorWithIndex, mapWithIndex) import Data.Maybe (Maybe(..), maybe) import Data.Ord (class Ord1) import Data.Semigroup.Foldable (class Foldable1, foldMap1) +import Data.Semigroup.Foldable (foldl1) as Foldable1 import Data.Traversable (class Traversable, traverse, sequence) import Data.TraversableWithIndex (class TraversableWithIndex, traverseWithIndex) import Data.Tuple (uncurry) import Data.Unfoldable (class Unfoldable, unfoldr) import Data.Unfoldable1 (class Unfoldable1) +import Prim.TypeError (class Warn, Text) -- | A non-empty container of elements of type a. -- | @@ -47,8 +49,8 @@ singleton :: forall f a. Plus f => a -> NonEmpty f a singleton a = a :| empty -- | Fold a non-empty structure, collecting results using a binary operation. -foldl1 :: forall f a. Foldable f => (a -> a -> a) -> NonEmpty f a -> a -foldl1 f (a :| fa) = foldl f a fa +foldl1 :: forall f a. Foldable f => Warn (Text "'foldl1' is deprecated") => (a -> a -> a) -> NonEmpty f a -> a +foldl1 = Foldable1.foldl1 fromNonEmpty :: forall f a r. (a -> f a -> r) -> NonEmpty f a -> r fromNonEmpty f (a :| fa) = a `f` fa @@ -108,7 +110,7 @@ instance foldable1NonEmpty :: Foldable f => Foldable1 (NonEmpty f) where fold1 = foldMap1 identity foldMap1 f (a :| fa) = foldl (\s a1 -> s <> f a1) (f a) fa foldr1 f (a :| fa) = maybe a (f a) $ foldr (\a1 -> Just <<< maybe a1 (f a1)) Nothing fa - foldl1 = foldl1 + foldl1 f (a :| fa) = foldl f a fa instance unfoldable1NonEmpty :: Unfoldable f => Unfoldable1 (NonEmpty f) where unfoldr1 f b = uncurry (:|) $ unfoldr (map f) <$> f b From 9acc7d4783d9c81d0654ce1ba4e91428a63d343a Mon Sep 17 00:00:00 2001 From: Cyril Sobierajewicz Date: Wed, 25 Nov 2020 09:34:53 +0100 Subject: [PATCH 2/2] Suggest the polymorphic foldl1 from Data.Semigroup.Foldable instead --- src/Data/NonEmpty.purs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/NonEmpty.purs b/src/Data/NonEmpty.purs index 5e7df4a..60e8003 100644 --- a/src/Data/NonEmpty.purs +++ b/src/Data/NonEmpty.purs @@ -49,7 +49,7 @@ singleton :: forall f a. Plus f => a -> NonEmpty f a singleton a = a :| empty -- | Fold a non-empty structure, collecting results using a binary operation. -foldl1 :: forall f a. Foldable f => Warn (Text "'foldl1' is deprecated") => (a -> a -> a) -> NonEmpty f a -> a +foldl1 :: forall f a. Foldable f => Warn (Text "'Data.NonEmpty.foldl1' is deprecated, use 'Data.Semigroup.Foldable.foldl1' instead") => (a -> a -> a) -> NonEmpty f a -> a foldl1 = Foldable1.foldl1 fromNonEmpty :: forall f a r. (a -> f a -> r) -> NonEmpty f a -> r