Skip to content

Commit

Permalink
feat: port List.traverse (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
kim-em authored Nov 27, 2023
1 parent a652e09 commit 1065675
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Std/Data/List/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1628,4 +1628,12 @@ Example: if `f : Nat → list Nat → β`, `List.mapWithComplement f [1, 2, 3]`
def mapWithComplement {α β} (f : α → List α → β) : List α → List β :=
mapWithPrefixSuffix fun pref a suff => f a (pref ++ suff)

/--
Map each element of a `List` to an action, evaluate these actions in order,
and collect the results.
-/
protected def traverse [Applicative F] (f : α → F β) : List α → F (List β)
| [] => pure []
| x :: xs => List.cons <$> f x <*> List.traverse f xs

end List

0 comments on commit 1065675

Please sign in to comment.