builtin(list): implement List.walkBackwardsUntil

Signed-off-by: Prajwal S N <prajwalnadig21@gmail.com>
This commit is contained in:
Prajwal S N 2022-10-08 14:20:47 +05:30
parent fd42879dc4
commit cbceeff902
No known key found for this signature in database
GPG key ID: D0FECEE245BC2695
3 changed files with 65 additions and 0 deletions

View file

@ -61,6 +61,7 @@ interface List
sortAsc,
sortDesc,
reserve,
walkBackwardsUntil,
]
imports [
Bool.{ Bool },
@ -436,6 +437,13 @@ walkUntil = \list, initial, step ->
Continue new -> new
Break new -> new
## Same as [List.walkUntil], but does it from the end of the list instead.
walkBackwardsUntil : List elem, state, (state, elem -> [Continue state, Break state]) -> state
walkBackwardsUntil = \list, initial, func ->
when List.iterateBackwards list initial func is
Continue new -> new
Break new -> new
sum : List (Num a) -> Num a
sum = \list ->
List.walk list 0 Num.add