diff --git a/src/Data/List.purs b/src/Data/List.purs index 61a2106..a6cdc36 100644 --- a/src/Data/List.purs +++ b/src/Data/List.purs @@ -760,6 +760,6 @@ transpose ((x : xs) : xss) = -------------------------------------------------------------------------------- -- | Perform a fold using a monadic step function. -foldM :: forall m a b. Monad m => (a -> b -> m a) -> a -> List b -> m a -foldM _ a Nil = pure a -foldM f a (b : bs) = f a b >>= \a' -> foldM f a' bs +foldM :: forall m a b. Monad m => (b -> a -> m b) -> b -> List a -> m b +foldM _ b Nil = pure b +foldM f b (a : as) = f b a >>= \b' -> foldM f b' as diff --git a/src/Data/List/Lazy.purs b/src/Data/List/Lazy.purs index b9b7ca4..72d528b 100644 --- a/src/Data/List/Lazy.purs +++ b/src/Data/List/Lazy.purs @@ -742,12 +742,12 @@ transpose xs = -------------------------------------------------------------------------------- -- | Perform a fold using a monadic step function. -foldM :: forall m a b. Monad m => (a -> b -> m a) -> a -> List b -> m a -foldM f a xs = +foldM :: forall m a b. Monad m => (b -> a -> m b) -> b -> List a -> m b +foldM f b xs = case uncons xs of - Nothing -> pure a - Just { head: b, tail: bs } -> - f a b >>= \a' -> foldM f a' bs + Nothing -> pure b + Just { head: a, tail: as } -> + f b a >>= \b' -> foldM f b' as -- | Perform a right fold lazily foldrLazy :: forall a b. Z.Lazy b => (a -> b -> b) -> b -> List a -> b diff --git a/src/Data/List/NonEmpty.purs b/src/Data/List/NonEmpty.purs index aff7585..7fe595c 100644 --- a/src/Data/List/NonEmpty.purs +++ b/src/Data/List/NonEmpty.purs @@ -299,5 +299,5 @@ zip = zipWith Tuple unzip :: forall a b. NonEmptyList (Tuple a b) -> Tuple (NonEmptyList a) (NonEmptyList b) unzip ts = Tuple (map fst ts) (map snd ts) -foldM :: forall m a b. Monad m => (a -> b -> m a) -> a -> NonEmptyList b -> m a -foldM f a (NonEmptyList (b :| bs)) = f a b >>= \a' -> L.foldM f a' bs +foldM :: forall m a b. Monad m => (b -> a -> m b) -> b -> NonEmptyList a -> m b +foldM f b (NonEmptyList (a :| as)) = f b a >>= \b' -> L.foldM f b' as