Skip to content

Change foldM type signature to more closely match foldl #165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Data/List.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions src/Data/List/Lazy.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Data/List/NonEmpty.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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