Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
49 lines (32 sloc) 732 Bytes
#
# Krill Standard Library
#
# Functions
id = x -> x
const x y -> x
compose = f g -> f . g
not = x -> !x
min = a b -> if a < b then a else b
max = a b -> if a > b then a else b
# Lists
reduce = foldl
filter = p -> reduce (acc curr -> {
if (p curr) then (acc ++ [curr])
else acc
}) []
sum = reduce (acc curr -> acc + curr) 0
flatten = reduce (flat toFlatten -> {
if (isList toFlatten) then flat ++ flatten(toFlatten)
else flat ++ [toFlatten]
}) []
join = delim xs -> reduce (a b -> a ++ b) "" $ intersperse delim xs
# Strings
lines = split "\n"
words = xs -> filter (x -> x != "") $ split " " xs
# Math
pow = x n -> {
if n == 1 then x
else x * (pow x (n - 1))
}
sqrt = root 2
pi = 3.14159265358979323846
You can’t perform that action at this time.