Skip to content

Commit 6aa1eac

Browse files
authored
Change foldM type signature to more closely match foldl (#165)
* Change foldM type signature to more closely match foldl
1 parent eef0256 commit 6aa1eac

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/Data/List.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,6 @@ transpose ((x : xs) : xss) =
760760
--------------------------------------------------------------------------------
761761

762762
-- | Perform a fold using a monadic step function.
763-
foldM :: forall m a b. Monad m => (a -> b -> m a) -> a -> List b -> m a
764-
foldM _ a Nil = pure a
765-
foldM f a (b : bs) = f a b >>= \a' -> foldM f a' bs
763+
foldM :: forall m a b. Monad m => (b -> a -> m b) -> b -> List a -> m b
764+
foldM _ b Nil = pure b
765+
foldM f b (a : as) = f b a >>= \b' -> foldM f b' as

src/Data/List/Lazy.purs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -727,12 +727,12 @@ transpose xs =
727727
--------------------------------------------------------------------------------
728728

729729
-- | Perform a fold using a monadic step function.
730-
foldM :: forall m a b. Monad m => (a -> b -> m a) -> a -> List b -> m a
731-
foldM f a xs =
730+
foldM :: forall m a b. Monad m => (b -> a -> m b) -> b -> List a -> m b
731+
foldM f b xs =
732732
case uncons xs of
733-
Nothing -> pure a
734-
Just { head: b, tail: bs } ->
735-
f a b >>= \a' -> foldM f a' bs
733+
Nothing -> pure b
734+
Just { head: a, tail: as } ->
735+
f b a >>= \b' -> foldM f b' as
736736

737737
-- | Perform a right fold lazily
738738
foldrLazy :: forall a b. Z.Lazy b => (a -> b -> b) -> b -> List a -> b

src/Data/List/NonEmpty.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,5 +299,5 @@ zip = zipWith Tuple
299299
unzip :: forall a b. NonEmptyList (Tuple a b) -> Tuple (NonEmptyList a) (NonEmptyList b)
300300
unzip ts = Tuple (map fst ts) (map snd ts)
301301

302-
foldM :: forall m a b. Monad m => (a -> b -> m a) -> a -> NonEmptyList b -> m a
303-
foldM f a (NonEmptyList (b :| bs)) = f a b >>= \a' -> L.foldM f a' bs
302+
foldM :: forall m a b. Monad m => (b -> a -> m b) -> b -> NonEmptyList a -> m b
303+
foldM f b (NonEmptyList (a :| as)) = f b a >>= \b' -> L.foldM f b' as

0 commit comments

Comments
 (0)