Add List.walk! function

This commit is contained in:
Ian McLerran 2024-12-30 13:34:26 -06:00
parent cb762688de
commit 53915bc6e1
No known key found for this signature in database
GPG key ID: 022CF95852BFF343

View file

@ -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!