• prelude.ls is a functionally oriented utility library.
  • It is powerful and flexible.
  • Almost all of its functions are curried.
  • It is written in, and is the recommended base library for, LiveScript.
[1 to 5] |> map (^2) |> filter even |> fold (+), 0 #=> 20

Install via npm: npm install prelude-ls. MIT License. Changelog.

for updates on prelude.ls releases.

You can report bugs and discuss features on the issue page.

Curried functions

Calling with less than the full number of arguments returns a partially applied function.

fold (+), 0, [1 2 3] #=> 6

sum = fold (+), 0
sum [1 2 3] #=> 6
sum [4 5 6] #=> 15

Installation

Install via npm: npm install prelude-ls.

For use in the browser, just include the prelude-browser-min.js file, and then use prelude = require 'prelude-ls'

If you wish, you may use an underscore to refer to the library, _ = require 'prelude-ls', and then _.map f, xs

However, the preferred way to use the library is to grab what you need from it using object deconstruction: {map, filter, lines} = require 'prelude-ls', and then simply map f, xs


Function Reference

The prelude object has several sub-modules, List, Obj, Str, Func, and Num.

Almost all the functions in these modules are added to the main object which you recieve when you require prelude. However, in some cases, especially where the names conflict, you will have to use the functions through the module, eg. Obj.map conflicts with List.map, so map refers to List.map and you must use Obj.map to use the version which operates on objects.

id
a → a

A function which does nothing: it simply returns its single argument. Useful as a placeholder.

id 5  #=> 5
id {} #=> {}
is-type
String → a → Boolean

Takes a string (type name) and a value, and returns if the value is of that type. Uses LiveScript's typeof! operator.

is-type 'Undefined' void #=> true
is-type 'Boolean' true   #=> true
is-type 'Number' 1       #=> true
is-type 'String' 'hi'    #=> true
is-type 'Object' {}      #=> true
is-type 'Array' []       #=> true
is-type 'HTMLBodyElement' (document.query-selector 'body') #=> true
replicate
Number → a → [a]

Takes its second argument, and replicates it n times to create a new list.

replicate 4 3   #=> [3, 3, 3, 3]
replicate 4 'a' #=> ['a', 'a', 'a', 'a']
replicate 0 'a' #=> []
List
each
(a → Undefined) → [a] → [a]

Applies a function to each item in the list and returns the original list. Used for side effects.

each (.push \boom), [['a'] ['b'] ['c']]
#=> [['a', 'boom'], ['b', 'boom'], ['c', 'boom']]
map
(a → b) → [a] → [b]

Applies a function to each item in the list, and produces a new list with the results. The length of the result is the same length as the input.

map (* 2), [1 to 5]                 #=> [2, 4, 6, 8, 10]
map (.to-upper-case!), ['ha', 'ma'] #=> ['HA', 'MA']
map (.num), [{num: 3}, {num: 1}]    #=> [3, 1]
compact
[a] → [a]

Returns a new list which contains only the truthy values of the inputted list.

compact [0 1 false true '' 'ha'] #=> [1, true, 'ha']
filter
(a → Boolean) → [a] → [a]

Returns a new list composed of the items which pass the supplied function's test.

filter (< 3), [1 to 5] #=> [1, 2]
filter even, [3, 4, 0] #=> [4, 0]
reject
(a → Boolean) → [a] → [a]

Like filter, but the new list is composed of all the items which fail the function's test.

reject odd, [1 to 5] #=> [2, 4]
partition
(a → Boolean) → [a] → [[a], [a]]

Equivalent to [(filter f, xs), (reject f, xs)], but more efficient, using only one loop.

partition (> 60), [49 58 76 43 88 77 90] #=> [[76 88 77 90],[49 58 43]]
find
(a → Boolean) → [a] → Maybe a

Returns the first item in list to pass the function's test. Returns undefined if all items fail the test.

find odd, [2 4 6 7 8 9 10] #=> 7
tail
[a] → [a]

Everything but the first item of the list.

tail [1 to 5] #=> [2, 3, 4, 5]
last
[a] → Maybe a

The last item of the list. Returns undefined if the list is empty.

last [1 to 5] #=> 5
initial
[a] → [a]

Everything but the last item of the list.

initial [1 to 5] #=> [1, 2, 3, 4]
empty
[a] → Boolean

Whether the list is empty.

empty [] #=> true
reverse
[a] → [a]

Returns a new list which is the reverse of the inputted one.

reverse [1 2 3] #=> [3, 2, 1]
unique
[a] → [a]

Returns a new list which contains each value of the inputted list only once.

unique [1 1 1 3 3 6 7 8] #=> [1 3 6 7 8]
unique-by
(a → b) → [a] → [a]

Returns a new list which contains each item which has a unique value when applied to the supplied function. If there are multiple different items with the same value when the function is applied, the first item is taken.

unique-by (.length), <[ and here are some words ]> #=> ['and', 'here', 'words']
fold
alias: foldl
(a → b → a) → a → [b] → a

Takes a list of items, and using the binary function supplied, folds them into a single value. Requires an initial value (the second argument), which will be the starting point, and result in case of an empty list.

fold (+), 0, [1 to 5] #=> 15
product = fold (*), 1
fold1
alias: foldl1
(a → a → a) → [a] → a

Like fold, except assumes a non-empty list, and thus doesn't require an initial value.

fold1 (+), [1 to 3] #=> 6
foldr
(a → b → b) → b → [a] → b

Like fold, except folding from the right instead of the left.

foldr (-), 9, [1 2 3 4]       #=> 7
foldr (+), 'e', <[ a b c d ]> #=> 'abcde'
foldr1
(a → a → a) → [a] → a

Like foldr, except assumes a non-empty list, and thus doesn't require an initial value.

foldr1 (-), [1 2 3 4 9] #=> 7
unfoldr
(b → Maybe [a, b]) → b → [a]

Unfoldr builds a list from a seed value (the second argument). It takes a function which either returns null if it is done producing the list, or returns [x, y], x which is prepended to the list, and y is used as the next element in the recursive call.

unfoldr (-> if it == 0 then null else [it, it - 1]), 10
#=> [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
concat
[[a]] → [a]

Concatenates a list of lists together.

concat [[1] [2 3] [4]]   #=> [1, 2, 3, 4]
concat-map
(a → [b]) → [a] → [b]

Like map, except concatenates the output.

concat-map (-> [1 to it]), [1 2 3] #=> [1, 1, 2, 1, 2, 3]
flatten
List → List

Flattens a list which contains sub lists and elements of arbitrary depth into a list of elements with no sub lists.

flatten [1, [[2], 3], [4, [[5]]]] #=> [1, 2, 3, 4, 5]
difference
([a], [a], ...) → [a]

Returns a new list containing the elements which are present in the first list and not in the others. This function is not curried as it takes a variable number of arguments.

difference [1 2 3] [1]              #=> [2, 3]
difference [1 2 3 4 5] [5 2 10] [9] #=> [1, 3, 4]
intersection
([a], [a], ...) → [a]

Produces a new list containing all the items which are present in all the lists. This function is not curried as it takes a variable number of arguments.

intersection [2 3] [9 8] [12 1] [99]               #=> []
intersection [1 2 3] [101 2 1 10] [2 1] [-1 0 1 2] #=> [1, 2]
intersection [1 2 3] [2 1 3] [3 1 2]               #=> [1, 2, 3]
union
([a], [a], ...) → [a]

Produces a new list containing all the elements of all the inputted lists only once. This function is not curried as it takes a variable number of arguments.

union [1 5 7] [3 5] [] #=> [1 5 7 3]
count-by
(a → b) → [a] → {b: Number}

Takes a list of items, and a function, and produces an object whose keys are the result of applying the function to the inputted list, and whose values are the number of its occurrences.

count-by floor, [4.2, 6.1, 6.4]         #=> {4: 1, 6: 2}
count-by (.length), <[ one two three ]> #=> {3: 2, 5: 1}
group-by
(a → b) → [a] → {b: [a]}

Takes a list of items, and a function, and produces an object whose keys are the result of applying the function to the inputted list, and whose values are a list of all the occurrences.

group-by floor, [4.2, 6.1, 6.4]         #=> {4: [4.2], 6: [6.1, 6.4]}
group-by (.length), <[ one two three ]> #=> {3: ['one', 'two'], 5: ['three']}
and-list
[a] → Boolean

Returns false if any item in the list is false, otherwise returns true.

and-list [true, 2 + 2 == 4] #=> true
and-list [true true false ] #=> false
and-list []                 #=> true
or-list
[a] → Boolean

Returns true if any item in the list is true, otherwise returns false.

or-list [false false true false] #=> true
or-list []                       #=> false
any
(a → Boolean) → [a] → Boolean

Returns true if any of the items in the list are true when applied to the test.

any even, [3, 5, 7, 8, 9] #=> true
any even, []              #=> false
all
(a → Boolean) → [a] → Boolean

Returns true if all the items in the list are true when applied to the test.

all (is-type 'String'), <[ ha ma la ]> #=> true
all (is-type 'String'), []             #=> true
sort
[a] → [a]

Sorts a list. Does not modify the input.

sort [3 1 5 2 4 6] #=> [1, 2, 3, 4, 5, 6]
sort-with
(a → a → Number) → [a] → [a]

Takes a binary function which compares two items and returns either a positive number, 0, or a negative number, and sorts the inputted list using that function. The original list is not modified.

f = (x, y) ->
  | x.length > y.length => 1
  | x.length < y.length => -1
  | otherwise           => 0
sort-with f, <[ three one two ]> #=> ['one','two','three']
sort-by
(a → b) → [a] → [a]

Sorts a list using the inputted function for making the comparison between the items.

sort-by (.length), arr #=> ['a', 'ha', 'hey', 'there']

table =
  * id: 1
    name: 'george'
  * id: 2
    name: 'mike'
  * id: 3
    name: 'donald'
sort-by (.name), table
#=> [{"id":3,"name":"donald"},{"id":1,"name":"george"},{"id":2,"name":"mike"}]
sum
[Number] → Number

Sums up the values in the list.

sum [1 to 5] #=> 15
sum []       #=> 0
product
[Number] → Number

Gets the product of all the items in the list.

product [1 2 3] #=> 6
product []      #=> 1
mean
alias: average
[Number] → Number

Gets the mean of the values in the list.

mean [1 to 5] #=> 3
maximum
[a] → a

Takes a list of comparable items, and returns the largest of them.

maximum [4 1 9 3] #=> 9
minimum
[a] → a

Takes a list of comparable items, and returns the smallest of them.

minimum ['c', 'e', 'a', 'd', 'b'] #=> 'a'
maximum-by
(a → b) → [a] → a

Takes a list of items, and returns the item with the largest value resulting from applying the supplied function to that item.

maximum-by (.length), <[ hi there I am looooong ]> #=> 'looooong'
minimum-by
(a → b) → [a] → a

Takes a list of items, and returns the item with the smallest value resulting from applying the supplied function to that item.

minimum-by (.length), <[ hi there I am looooong ]> #=> 'I'
scan
alias: scanl
(a → b → a) → a → [b] → [a]

Like fold, except instead of just returning the final value, returns a list composed of the initial value, the intermediate values, and then the final value. Requires an initial value (the second argument), which is used case of an empty list.

scan (+), 0, [1 to 3] #=> [0, 1, 3, 6]
scan1
alias: scanl1
(a → a → a) → [a] → [a]

Like scan, except assumes non-empty list, and thus doesn't require an initial value.

scan1 (+), [1 to 3] #=> [1, 3, 6]
scanr
(a → b → b) → b → [a] → [b]

Like scan, except from the right.

scanr (+), 0, [1 to 3] #=> [6, 5, 3, 0]
scanr1
(a → a → a) → [a] → [a]

Like scanr, except assumes non-empty list, and thus doesn't require an initial value.

scanr1 (+), [1 to 3] #=> [6, 5, 3]
slice
Number → Number → [a] → [a]

Returns a slice of a list.

slice 2 4 [1 2 3 4 5] #=> [3, 4]
take
Number → [a] → [a]

Returns the first n items in the list.

take 2 [1 to 5] #=> [1, 2]
drop
Number → [a] → [a]

Returns the result of dropping the first n items of the list.

drop 2 [1 to 5] #=> [3, 4, 5]
split-at
Number → [a] → [[a], [a]]

Equivalent to [(take n, xs), (drop n, xs)]

split-at 2 [1 to 5] #=> [[1, 2], [3, 4, 5]]
take-while
(a → Boolean) → [a] → [a]

Takes the first items of the list which pass the test.

take-while odd, [1 3 5 4 8 7 9] #=> [1, 3, 5]
drop-while
(a → Boolean) → [a] → [a]

Drops the first items of the list which pass the test.

drop-while even, [2 4 5 6] #=> [5, 6]
span
(a → Boolean) → [a] → [[a], [a]]

Equivalent to [(take-while f, xs), (drop-while f, xs)]

span even, [2 4 5 6] #=> [[2, 4], [5, 6]]
break-list
(a → Boolean) → [a] → [[a], [a]]

Equivalent to span (not) << f, xs

break-list (== 3), [1 to 5] #=> [[1, 2], [3, 4, 5]]
zip
[a] → [b] → [[a, b]]

Zips together its two arguments into a list of lists.

zip [1 2 3] [4 5 6] #=> [[1, 4], [2, 5], [3, 6]]
zip-with
(a → b → c) → [a] → [b] → [c]

Zips together its two arguments using a function into a list of resulting values.

zip-with (+), [1 2 3] [4 5 6] #=> [5, 7, 9]
zip-all
([a], [b], [c], ...) → [[a, b, c, ...]]

Zips together its arguments into a list of lists. This function is not curried as it takes a variable number of arguments.

zip-all [1 2 3] [4 5 6] [7 8 9] #=> [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
zip-all-with
((a, b, c, ... → d), [a], [b], [c], ...) → [d]

As zip-all, but applies the supplied function to the lists and creates a list of the results. The supplied function must take in as many arguments as there are lists being inputed. This function is not curried as it takes a variable number of arguments.

zip-all-with (-> &0 + &1 + &2), [1 2 3], [3 2 1] [1 1 1] #=> [5, 5, 5]
at
Number → [a] → a

Gets the element at the nth index (the first argument). If negative, will work from the end.

at 2, [1 2 3 4] #=> 3
at -3, [1 2 3 4] #=> 2
elem-index
a → [a] → Number

Returns the index of the first occurrence of the supplied element in the list. Returns undefined if the element is not found.

elem-index 'a', <[ c a b a ]> #=> 1
elem-indices
a → [a] → [Number]

Returns an array of all the indices of the supplied element in the list. Returns an empty list if the element is not found at all.

elem-indices 'a', <[ c a b a ]> #=> [1, 3]
find-index
(a → Boolean) → [a] → Number

Returns the index of the first element to pass the predicate. Returns undefined if the predicate never passes.

find-index even, [1 2 3 4] #=> 1
find-indices
(a → Boolean) → [a] → [Number]

Returns an array of all the indices of the elements which pass the predicate. Returns an empty list if the predicate never passes.

find-indices even, [1 2 3 4] #=> [1, 3]
Obj
keys
{a: b} → [a]

Returns a list of the keys of the object.

keys a: 2, b: 3, c: 9 #=> ['a', 'b', 'c']
values
{a: b} → [b]

Returns a list of the values of the object.

values a: 2, b: 3, c: 9 #=> [2, 3, 9]
pairs-to-obj
[[a, b]] → {a: b}

Takes a list of pairs and turns them into an object.

pairs-to-obj [['a' 'b'] ['c' 'd'] ['e' 1]] #=> {a: 'b', c: 'd', e: 1}
obj-to-pairs
{a: b} → [[a, b]]

Takes an object and returns a list of pairs.

obj-to-pairs {a: 'b', c: 'd', e: 1} #=> [['a', 'b'], ['c', 'd'], ['e', 1]]
lists-to-obj
[a] → [b] → {a: b}

Takes two lists and zips them up into an object.

lists-to-obj <[ a b c ]> [1 2 3] #=> {a: 1, b: 2, c: 3}
obj-to-lists
{a: b} → [[a], [b]]

Takes an object and returns a list with two lists, one of its keys, one with its values.

obj-to-lists {a: 1, b: 2, c: 3} #=> [['a', 'b', 'c'], [1, 2, 3]]
Obj.empty
Object → Boolean

Whether the object is empty (has no enumerable keys).

Obj.empty {} #=> true
Obj.each
(b → Undefined) → {a: b} → {a: b}

Applies a function to each value in the object, and returns the original object. Used for side effects.

count = 4
Obj.each (-> count += it), {a: 1, b: 2, c: 3}
count #=> 10
Obj.map
(b → c) → {a: b} → {a: c}

Applies a function to each value of the object, and produces a new object with the same keys and the new values. The size of the result is the same size as the input.

Obj.map (+ 2), {a: 2, b: 3, c: 4} #=> {a: 4, b: 5, c: 6}
Obj.compact
{a: b} → {a: b}

Returns a new object which contains only the truthy values of the inputted object.

Obj.compact {a: 0, b: 1, c: false, d: '', e: 'ha'} #=> {b: 1, e: 'ha'}
Obj.filter
(b → Boolean) → {a: b} → {a: b}

Returns a new object composed of the values which pass the supplied function's test.

Obj.filter even, {a: 3, b: 4, c: 0} #=> {b: 4, c: 0}
Obj.reject
(b → Boolean) → {a: b} → {a: b}

Like filter, but the new object is composed of all the values which fail the function's test.

Obj.reject (== 2), {a:1, b:2} #=> {a: 1}
Obj.partition
(b → Boolean) → {a: b} → [{a: b}, {a: b}]

Equivalent to [(Obj.filter f, xs), (Obj.reject f, xs)], but more efficient, only using one loop.

Obj.partition (== 2), {a:1, b:2, c:3} #=> [{b: 2}, {a: 1, c: 3}]
Obj.find
(b → Boolean) → {a: b} → b

Returns the first value to pass the test.

Obj.find even, {a:1, b:2, c:3, d:4} #=> 2
Str
split
String → String → [String]

Splits a string on a separator into a list of strings.

split '|' '1|2|3' #=> ['1', '2', '3']
join
String → [String] → String

Joins a list with the specified separator.

join '|' [1 til 4] #=> '1|2|3'
lines
String → [String]

Splits a string at newlines into a list.

lines '''one
         two
         three'''
#=> ['one', 'two', 'three']
unlines
[String] → String

Joins a list of strings into a single string using newlines.

unlines [\one \two \three]
#=> 'one
#    two
#    three'
words
String → [String]

Splits a string at spaces (one or more), returning a list of strings.

words 'hello, what is that?'
#=> ['hello,', 'what', 'is', 'that?']
unwords
[String] → String

Joins a list of strings into a single string using spaces.

unwords ['one' 'two' 'three'] #=> 'one two three'
chars
String → [String]

Splits a string at every character, returning a list of one character strings.

chars 'hello' #=> ['h', 'e', 'l', 'l', 'o']
unchars
[String] → String

Joins a list of strings into a single string using no separator.

unchars ['t' 'h' 'e' 'r' 'e'] #=> 'there'
unchars ['ma', 'ma']          #=> 'mama'
repeat
Number → String → String

Takes its second argument, and repeats it n times to create a new, single, string.

repeat 4 'a'  #=> 'aaaa'
repeat 2 'ha' #=> 'haha'
capitalize
String → String

Capitalizes a string.

capitalize 'hi there' #=> 'Hi there'
camelize
String → String

Camelizes a string.

camelize 'hi-there' #=> 'hiThere'
camelize 'hi_there' #=> 'hiThere'
dasherize
String → String

Dasherizes a string.

dasherize 'hiThere' #=> 'hi-there'
dasherize 'FooBar' #=> 'foo-bar'
dasherize 'innerHTML' #=> 'inner-HTML'
Str.empty
String → Boolean

Whether the string is empty.

empty '' #=> true
Str.reverse
String → String

Reverses a string.

reverse 'goat'   #=> 'taog'
Str.slice
Number → Number → String → String

Returns a slice of the inputted string.

slice 2 4 'hello' #=> 'll'
Str.take
Number → String → String

Returns the first n items in string.

take 4 'hello'   #=> 'hell'
Str.drop
Number → String → String

Returns the result of dropping the first n items of the string.

drop 1 'goat'   #=> 'oat'
Str.split-at
Number → String → [String, String]

Equivalent to [(Str.take n, xs), (Str.drop n, xs)]

split-at 4 'hello' #=> ['hell', 'o']
Str.take-while
(String → Boolean) → String → String

Takes the first items of the string which pass the test.

take-while (in [\a to \d]), 'cabdek' #=> 'cabd'
Str.drop-while
(String → Boolean) → String → String

Drops the first items of the string which pass the test.

drop-while (is \m), 'mmmmmhmm' #=> 'hmm'
Str.span
(String → Boolean) → String → [String, String]

Equivalent to [(take-while f, xs), (drop-while f, xs)]

span (is \m), 'mmmmmhmm' #=> ['mmmmm', 'hmm']
Str.break-str
(String → Boolean) → String → [String, String]

Equivalent to span (not) << f, xs

Str.break-str (is \h), 'mmmmmhmm' #=> ['mmmmm', 'hmm']
Func
apply
(a → b → c → ... → d) → [a, b, c, ...] → d

Returns the application of the supplied list as arguments to the supplied function.

apply (+), [2 3] #=> 5
curry
Function → Function

Returns a curried version of the supplied function. Useful for currying functions from non-LiveScript libraries.

add = (x, y) -> x + y
add-curried = curry add
add-four = add-curried 4
add-four 2 #=> 6
flip
(a → b → c) → (b → a → c)

Returns a function with the arguments flipped.

inverted-power = flip (^)
inverted-power 2 3 #=> 9
fix
(Function → Function) → Function

Fix-point function for anonymous recursion, implemented with the Y combinator.

(fix (fib) -> (n) ->
   | n <= 1      => 1
   | otherwise   => fib(n-1) + fib(n-2))(9) #=> 55
over
(b → c) → (a → b) → a → a → (a → c)

Combines two functions: (f, g, x, y) --> f (g x), (g y). Looks nice when applied infix.

same-length = (==) `over` (.length)
same-length 'hi', 'me'    #=> true
same-length 'one', 'boom' #=> false
memoize
Function → Function

Caches computed results, speeding up later calls with the same arguments.

f = memoize expensive-function
f 2 # slow, but result is then cached
f 2 # fast
Num
max
Comparable → Comparable → Value

Takes two arguments which can be compared using >, returns the larger one.

max 3 1     #=> 3
max 'a' 'c' #=> 'c'
min
Comparable → Comparable → Value

Takes two arguments which can be compared using >, returns the smaller one.

min 3 1     #=> 1
min 'a' 'c' #=> 'a'
negate
Number → Number

The negation of the inputted number.

negate 3  #=> -3
negate -2 #=>  2
abs
Number → Number

Takes a number and returns its absolute value.

abs -2 #=>  2
abs 2  #=> 2
signum
Number → (-1 | 0 | 1)

Takes a number and returns either -1, 0, or 1 depending on the sign of the number.

signum -5 #=> -1
signum  0 #=>  0
signum  9 #=>  1
quot
Number → Number → Number

Division truncated toward 0.

quot -20 3 #=> -6
rem
Number → Number → Number

Remainder, like the % operator.

rem -20 3 #=> -2
div
Number → Number → Number

Division truncated down toward negative infinity.

div -20 3 #=> -7
mod
Number → Number → Number

Remainder, like the %% operator in LiveScript.

mod -20 3 #=> 1
recip
Number → Number

One over the number, ie 1 / x

recip 4 #=> 0.25
pi
Number

π

pi #=> 3.141592653589793
tau
Number

τ (2π)

tau #=> 6.283185307179586
exp
Number → Number

Returns e to the argument.

exp 1 #=> 2.718281828459045
sqrt
Number → Number

Square root.

sqrt 4 #=> 2
ln

Natural log.

Number → Number
ln 10 #=> 2.302585092994046
pow
Number → Number → Number

Power. Equivalent to x ^ y or x ** y in LiveScript.

pow -2 2 #=> 4
sin
Number → Number
sin pi/2 #=> 1
cos
Number → Number
cos pi #=> -1
tan
Number → Number
tan pi/4 #=> 1
asin
Number → Number
asin 0 #=> 0
acos
Number → Number
acos 1 #=> 0
atan
Number → Number
atan 0 #=> 0
atan2
Number → Number → Number
atan2 1 0 #=> 1.5707963267948966
truncate
Number → Number

Number truncated toward 0.

truncate -1.5 #=> -1
truncate  1.5 #=>  1
round
Number → Number

Number rounded to nearest whole number.

round 0.6 #=> 1
round 0.5 #=> 1
round 0.4 #=> 0
ceiling
Number → Number

Number rounded up.

ceiling 0.1 #=> 1
floor
Number → Number

Number rounded down.

floor 0.9 #=> 0
is-it-NaN
Number → Boolean

Is it NaN (not a number)? More accurate than the native isNaN function.

is-it-NaN sqrt -1 #=> true
even
Number → Boolean

Is the number even?

even 4 #=> true
even 0 #=> true
odd
Number → Boolean

Is the number odd?

odd 3 #=> true
gcd
Number → Number → Number

Greatest common denominator.

gcd 12 18 #=> 6
lcm
Number → Number → Number

Least common multiple.

lcm 12 18 #=> 36