Skip to content
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

chore: List.filterMapM runs and returns left-to-right #4820

Merged
merged 1 commit into from
Jul 24, 2024
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
4 changes: 2 additions & 2 deletions src/Init/Data/List/Control.lean
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ results `y` for which `f x` returns `some y`.
@[inline]
def filterMapM {m : Type u → Type v} [Monad m] {α β : Type u} (f : α → m (Option β)) (as : List α) : m (List β) :=
let rec @[specialize] loop
| [], bs => pure bs
| [], bs => pure bs.reverse
| a :: as, bs => do
match (← f a) with
| none => loop as bs
| some b => loop as (b::bs)
loop as.reverse []
loop as []

/--
Folds a monadic function over a list from left to right:
Expand Down
6 changes: 3 additions & 3 deletions tests/lean/run/array1.lean
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ def tst : IO (List Nat) :=
(if x % 2 == 0 then pure $ some (x + 10) else pure none)

/--
info: 4
3
info: 1
2
1
3
4
[12, 14]
-/
#guard_msgs in
Expand Down
Loading