Add more new fns
This commit is contained in:
parent
36d9ed8d69
commit
421114f191
|
@ -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!
|
||||||
|
|
Loading…
Reference in New Issue
Block a user