add foldr
This commit is contained in:
parent
763219d111
commit
fe029573cf
17
prelude.ld
17
prelude.ld
|
@ -228,6 +228,22 @@ fn fold {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
fn foldr {
|
||||
"Folds a list, right-associative."
|
||||
(f as :fn, []) -> []
|
||||
(f as :fn, xs as :list) -> fold (f, xs, f ())
|
||||
(f as :fn, [], root) -> []
|
||||
(f as :fn, xs as :list, root) -> loop (root, first (xs), rest (xs)) with {
|
||||
(prev, curr, []) -> f (curr, prev)
|
||||
(prev, curr, remaining) -> recur (
|
||||
f (curr, prev)
|
||||
first (remaining)
|
||||
rest (remaining)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
& TODO: optimize these with base :conj!
|
||||
fn map {
|
||||
"Maps a function over a list: returns a new list with elements that are the result of applying the function to each element in the original list. E.g., `map ([1, 2, 3], inc) &=> [2, 3, 4]`."
|
||||
|
@ -1359,6 +1375,7 @@ pkg Prelude {
|
|||
floor & math
|
||||
fn? & functions
|
||||
fold & lists
|
||||
foldr & lists
|
||||
forward! & turtles
|
||||
get & dicts
|
||||
goto! & turtles
|
||||
|
|
Loading…
Reference in New Issue
Block a user