Add more new fns

This commit is contained in:
Scott Richmond 2023-12-13 17:08:15 -05:00
parent 36d9ed8d69
commit 421114f191

View File

@ -189,6 +189,21 @@ fn map {
} }
} }
fn filter {
"Takes a list and a predicate function, and returns a new list with only the items that produce truthy values when the function is called on them."
(p? as :fn, xs) -> {
fn filterer (filtered, x) -> if p? (x)
then append (filtered, x)
else filtered
fold (filterer, xs, [])
}
}
fn keep {
"Takes a list and returns a new list with any `nil` values omitted."
(xs) -> filter (some?, xs)
}
fn append { fn append {
"Adds an element to a list or set." "Adds an element to a list or set."
() -> [] () -> []
@ -1139,6 +1154,8 @@ fn penwidth {
ns prelude { ns prelude {
type type
eq? eq?
neq?
tuple?
fn? fn?
first first
second second
@ -1151,8 +1168,11 @@ ns prelude {
append append
fold fold
map map
filter
keep
list list
set set
set?
inc inc
dec dec
print! print!
@ -1164,6 +1184,7 @@ ns prelude {
panic! panic!
doc! doc!
concat concat
ref?
deref deref
make! make!
update! update!