mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
Add List.walk! function
This commit is contained in:
parent
cb762688de
commit
53915bc6e1
1 changed files with 12 additions and 0 deletions
|
@ -1466,3 +1466,15 @@ forEachTry! = \list, func! ->
|
|||
|
||||
Err err ->
|
||||
Err err
|
||||
|
||||
## Build a value from the contents of a list, using an effectful function.
|
||||
##
|
||||
## This is the same as [walk], except that the step function can have effects.
|
||||
walk! : List elem, state, (state, elem => state) => state
|
||||
walk! = \list, init, func! ->
|
||||
when list is
|
||||
[] -> state
|
||||
|
||||
[elem, .. as rest] ->
|
||||
nextState = func! state elem
|
||||
walk! rest nextState func!
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue