Global

Methods

and(…args) → {*}

evaluates expressions from left to right and returns the first argument that is falsy or the last arg if all args are truthy
Parameters:
Name Type Attributes Description
args * <repeatable>
Source:
Returns:
Type
*
Example
and(true, true);
// => true

and([], []);
// => []

and(0, 1);
// => 1

assoc(coll, key, value) → {Array}

returns a new structure with a modified values
Parameters:
Name Type Description
coll Array | Map | Object
key number | string
value *
Source:
Returns:
Type
Array
Example
assoc([1, 2, 5, 6, 8, 9], 0, 77);
// => [77, 2, 5, 6, 8, 9]

assocIn(coll) → {Array}

assocIn() associates a value in a nested structure. It returns a new structure
Parameters:
Name Type Description
coll Array | May | object
Source:
Returns:
Type
Array
Example
assocIn([{name: "George", age: 12}, {name: "Lola", age: 11}], [0, "age"], 13);
// => [
//      { name: "George", age: 13 },
//      { name: "Lola", age: 11 },
//    ];

atom(value) → {Atom}

Atoms provide a way to manage state
Parameters:
Name Type Description
value *
Source:
Returns:
Type
Atom
Example
var myAtom = atom(0);
myAtom;
// => Atom {
//      value: 0,
//      _deref: [Function (anonymous)],
//      _mutReset: [Function (anonymous)]
//   }

deref(myAtom);
// => 0

mutSwap(myAtom, inc);
// => 1

mutSwap(myAtom, function(n) { return (n + n) * 2 });
// => 4

mutReset(myAtom, 0);

deref(myAtom);
// => 0

booleans(x) → {boolean}

returns x coerced to a boolean
Parameters:
Name Type Description
x *
Source:
Returns:
Type
boolean
Example
booleans("hello");
// => true

booleans(0)
// => false

butlast()

returns a sequence of all but the last item in coll butlast([1, 2, 3]); // => [1, 2]
Source:

classOf(x) → {Class}

returns the class of x
Parameters:
Name Type Description
x *
Source:
Returns:
Type
Class
Example
classOf("hello");
// => [Function: String]

classOf(false);
// => [Function: Boolean]

classOf(1);
// => [Function: Number]

classOf(function() {});
// => [Function: Function]

classOf(new Map());
// => [Function: Map]

classOf([]);
// => [Function: Array]

classOf({});
// => [Function: Object]

classOf(new List());
// => [class List extends Array]

classOf(new Set);
// => [Function: Set]

classOf(new LazyIterable);
// => [class LazyIterable]

comp(…fs) → {*}

takes a set of functions and returns a fn that is the composition of those fns
Parameters:
Name Type Attributes Description
fs function <repeatable>
Source:
Returns:
Type
*
Example
comp(isZero)(5);
// => false

comp(str, plus)(8, 8, 8);
// => "24"

complement(f) → {function}

takes a fn f and returns a fn that takes the same arguments as f, has the same effects, if any, and returns the opposite truth value
Parameters:
Name Type Description
f function
Source:
Returns:
Type
function
Example
var testIsOdd = complement(isEven);
testIsOdd(3);
// => true

concat(…colls) → {LazyIterable}

returns a lazy sequence of the concatenation of elements in colls
Parameters:
Name Type Attributes Description
colls Array <repeatable>
Source:
Returns:
Type
LazyIterable
Example
[...concat([1, 2], [3, 4])];
// => [1, 2, 3, 4]

[...concat(["a", "b"], null, [1, [2, 3], 4])];
// => ["a", "b", 1, [2, 3], 4]

cond(…xs)

takes a set of test / expression pairs. It evaluates each test one at a time returning the result for the first true test
Parameters:
Name Type Attributes Description
xs Array <repeatable>
Source:
Returns:
{function
Example
function posNegOrZero(n) {
  return cond(
    [() => n < 0, () => "negative"],
    [() => n > 0, () => "positive"],
    [() => "else", () => "zero"]
  )();
}
posNegOrZero(5);
// => "positive"

conj(xs) → {Set|Array|List|Map|Object}

conj() (conjoin) adds to a structure and returns a copy. The position of the addition depends on the structure type
Parameters:
Name Type Description
xs Set | Array | List | Map | Object
*
Source:
Returns:
Type
Set | Array | List | Map | Object
Example
conj([1, 2, 3], 4);
// => [1, 2, 3, 4]

conj([1, 2, 3], 4, 5);
// => [1, 2, 3, 4, 5]

cons(x, coll) → {LazyIterable}

returns a new LazyIterable where x is the first item and coll is the rest
Parameters:
Name Type Description
x *
coll Array | List | Map | Set | Object | string | null
Source:
Returns:
Type
LazyIterable
Example
[...cons(1, [2, 3, 4, 5, 6])];
// => [1, 2, 3, 4, 5, 6]

[...cons([1, 2], [4, 5, 6])];
// => [[1, 2], 4, 5, 6]

constantly(x) → {function}

constantly returns a function that takes any number of arguments and returns x
Parameters:
Name Type Description
x *
Source:
Returns:
Type
function
Example
var boring = constantly(10);
boring()
// => 10

boring("hello");
// => 10

count(coll) → {number}

returns the number of items in the collection
Parameters:
Name Type Description
coll *
Source:
Returns:
Type
number
Example
count([1, 2, 3]);
// => 3

cycle(coll) → {LazyIterable}

returns a lazy sequence of repetitions from items in coll
Parameters:
Name Type Description
coll Array | Map | List | Set | Object | string | null
Source:
Returns:
Type
LazyIterable
Example
[...take(5, cycle(["a", "b"]))];
// => ["a", "b", "a", "b", "a"]

[...take(10, cycle(range(0, 3)))];
// => [0, 1, 2, 0, 1, 2, 0, 1, 2, 0]

dec(n) → {number}

returns a number one less than n
Parameters:
Name Type Description
n number
Source:
Returns:
Type
number
Example
dec(5);
// => 4

deref(ref) → {*}

returns the value stored in an atom
Parameters:
Name Type Description
ref Atom
Source:
Returns:
Type
*
Example
var myAtom = atom(0);
mutSwap(myAtom, inc);
deref(myAtom);
// => 1

disj(set) → {Set}

returns a new copy of a set with item(s) removed
Parameters:
Name Type Description
set Set
Source:
Returns:
Type
Set
Example
disj(new Set(["a", "b", "c"]), "b");
// => Set(2) { "a", "c" }

dissoc(object, …keys) → {Object}

returns a copy of an object with item(s) removed by key name
Parameters:
Name Type Attributes Description
object Object
keys string <repeatable>
Source:
Returns:
Type
Object
Example
dissoc({name: "George", salary: "Biscuits"}, "name", "salary");
// => {}

distinct(coll) → {LazyIterable}

returns a lazy sequnce of the elements of coll with duplicates removed
Parameters:
Name Type Description
coll Array | Map | List | Set | Object | string | null
Source:
Returns:
Type
LazyIterable
Example
[...distinct([1, 2, 1, 3, 1, 4, 1, 5])];
// => [1, 2, 3, 4, 5]

[...distinct(["a", "a", "b", "c"])];
// => ["a", "b", "c"]

apply(str, distinct("tattoo"));
// => "tao"

divide(…xs) → {number}

returns the division of numbers
Parameters:
Name Type Attributes Description
xs number <repeatable>
Source:
Returns:
Type
number
Example
divide(6, 3);
// => 2

divide(10);
// => 0.1

divide(6, 3, 2);
// => 1

drop(n, xs) → {LazySequence}

returns a lazy sequence of all but the first n items in coll
Parameters:
Name Type Description
n number
xs Array | List | Set | Object | string | null
Source:
Returns:
Type
LazySequence
Example
[...drop(-1, [1, 2, 3, 4])];
// => [1, 2, 3, 4]

[...drop(2, [1, 2, 3, 4])];
// => [3, 4]

dropLast(args) → {LazyIterable}

returns a lazy sequence of all but the last n items in coll
Parameters:
Name Type Description
args Array | Map | List | Set | Object | string | null
Source:
Returns:
Type
LazyIterable
Example
[...dropLast([1, 2, 3, 4])];
// => [1, 2, 3]

dropWhile(pred, xs) → {Array}

returns a lazy sequence of the items in coll starting from the first item for which pred(value) returns false
Parameters:
Name Type Description
pred function
xs Array | Map | List | Set | Object | string | null
Source:
Returns:
Type
Array
Example
[...dropWhile((x) => 3 > x, [1, 2, 3, 4, 5, 6])];
// => [3, 4, 5, 6]

[...dropWhile((x) => 3 >= x, [1, 2, 3, 4, 5, 6])];
// => [4, 5, 6]

empty(coll) → {Array|Map|Set|List|Object|null}

returns an empty coll of the same category as coll or null
Parameters:
Name Type Description
coll Array | Map | Set | List | Object | null
Source:
Returns:
Type
Array | Map | Set | List | Object | null
Example
empty(list(1, 2));
// => List(0) []

eq(x, y, …args) → {boolean}

compares x, y and args. Allows comparison of nested arrays and objects
Parameters:
Name Type Attributes Description
x *
y *
args * <repeatable>
Source:
Returns:
Type
boolean
Example
eq(5);
// => true

eq(1, 2);
// => false

eq(1, 1, 1);
// => true

eq([1, 2], [1, 2], [1, 2]);
// => true

eq([1, 2, [3, 4, [{a: "b"}]]], [1, 2, [3, 4, [{a: "b"}]]]);
// => true

everyPred(…predicates) → {function}

returns function which returns true if all predicates are true, false otherwise
Parameters:
Name Type Attributes Description
predicates function <repeatable>
Source:
Returns:
Type
function
Example
everyPred(isNumber, isOdd)(3, 9, 1);
// true

everyPred(isNumber, isEven)(3, 9, 1);
// false

everyPred(isNumber, isOdd, isPos)(3, 9, 1);
// true

ffirst(coll) → {*}

the same as first(first(coll))
Parameters:
Name Type Description
coll Array | List | Map | Set | Object | string | null
Source:
Returns:
Type
*
Example
ffirst({name: "George", weight: 100})
// => "name"

filter(predicate, collection)

returns a lazy sequence of the items in coll for which pred(item) returns true
Parameters:
Name Type Description
predicate function
collection Array | List | Set | null
Source:
Example
[...filter(isEven, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])];
// => [0, 2, 4, 6, 8, 10]

filterv(predicate, collection) → {Array}

returns an array of the items in coll for which pred(item) returns true
Parameters:
Name Type Description
predicate function check
collection Array | List | Set | null
Source:
Returns:
Type
Array
Example
filterv(isEven, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
// => [0, 2, 4, 6, 8, 10]

first(coll) → {*}

returns the first item of collection
Parameters:
Name Type Description
coll Array | List | Map | Set | Object | string | null
Source:
Returns:
Type
*
Example
first([1, 2, 3]);
// => 1

first("abc");
// => "a"

float(x) → {number}

coerces x to a float
Parameters:
Name Type Description
x string | number
Source:
Returns:
Type
number
Example
float("1.5");
// => 1.5

float(1);
// => 1

float(1.4442);
// => 1.4442

fnil(f, xs) → {function}

takes a function f, and returns a function that calls f, replacing a null first argument to f with the supplied value x
Parameters:
Name Type Description
f function
xs *
Source:
Returns:
Type
function
Example
function sayHello(name) {
  return str("Hello ", name);
}

var sayHelloWithDefaults = fnil(sayHello, "world");

sayHelloWithDefaults(null);
// => "Hello world"

sayHelloWithDefaults("universe");
// => "Hello universe"

frequencies(coll) → {Object}

returns an object from distinct items in coll to the number of times they appear
Parameters:
Name Type Description
coll Array | Map | List | Set | Object | string | null
Source:
Returns:
Type
Object
Example
frequencies(["a", "b", "a", "a"]);
// => {a: 3, b: 1}

get(coll) → {*}

returns the value mapped to key, notFound or null if the key is not present
Parameters:
Name Type Description
coll Array | List | Map | Set | Object | string
Source:
Returns:
Type
*
Example
get([1, 2, 3], 1);
// => 2

getIn(coll, path, notFound) → {*}

returns a selected value from a nested structure
Parameters:
Name Type Description
coll Array | Map | List | Set | Object
path Array
notFound *
Source:
Returns:
Type
*
Example
var pet = {
  name: "George",
  profile: {
    name: "George V",
    address: { city: "London", street: "Tabby Lane" },
  },
}

getIn(pet, ["profile", "name"]);
// => "George V"

groupBy(f, coll) → {Object}

returns an object of the elements of coll keyed by the result of f on each element
Parameters:
Name Type Description
f function
coll Array | List | Set | null
Source:
Returns:
Type
Object
Example
groupBy(isOdd, range(10));
// => {false: [0, 2, 4, 6, 8], true: [1, 3, 5, 7, 9]}

gt(…xs) → {boolean}

greater than (>) returns true if numbers are in decreasing order, otherwise false
Parameters:
Name Type Attributes Description
xs number <repeatable>
Source:
Returns:
Type
boolean
Example
gt(1, 2);
// => false

gt(2, 1);
// => true

gt(6, 5, 4, 3, 2)
// => true

identity(x) → {*}

returns its argument
Parameters:
Name Type Description
x *
Source:
Returns:
Type
*
Example
identity([1]);
// => [1]

ifNot(test, then, otherwise) → {*}

evaluates test. If false evaluates and returns then or otherwise (if supplied)
Parameters:
Name Type Description
test *
then *
otherwise *
Source:
Returns:
Type
*
Example
ifNot(isEmpty([1, 2]), first([1, 2]));
// => 1

ifNot(isEmpty([]), first([1, 2]));
// => null

iff(test, then, otherwise) → {*}

evaluates the test and returns then if true, otherwise if false
Parameters:
Name Type Description
test *
then *
otherwise *
Source:
Returns:
Type
*
Example
iff(1 > 2, "hello", "world");
"world"

iff(3 > 2, str("hello", " world"), "world");
"hello world"

iff(1 * 2 === 2, (() => 3 * 2)(), 7);
6

inc(n) → {number}

returns a number one greater than n
Parameters:
Name Type Description
n number
Source:
Returns:
Type
number
Example
inc(5);
// => 6

int(x) → {number}

coerces x to an integer
Parameters:
Name Type Description
x string | number
Source:
Returns:
Type
number
Example
int(1);
// => 1

int(1.2);
// => 1

interleave(colls) → {LazyIterable}

returns a lazy sequence of the first item in each coll, then the second etc
Parameters:
Name Type Description
colls Array | Map | Set | List | Object | string | null
Source:
Returns:
Type
LazyIterable
Example
[...interleave(["a", "b", "c"], [1, 2, 3])];
// => ["a", 1, "b", 2, "c", 3]

into(args) → {Array|Map|Set|Object}

returns a new coll containing values from colls conjoined
Parameters:
Name Type Description
args Array | Map | Set | Object | string | null
Source:
Returns:
Type
Array | Map | Set | Object
Example
into([], [1, 2, 3]);
// => [1, 2, 3]

isDistinct(xs) → {boolean}

returns true if no two of the arguments are equal, false otherwise
Parameters:
Name Type Description
xs *
Source:
Returns:
Type
boolean
Example
isDistinct(1, 2, 3);
// => true

isDistinct(1, 2, 3, 3);
// => false

isDistinct(["A", "A", "c"]);
// => true

isEmpty(coll) → {boolean}

returns true if coll has no items
Parameters:
Name Type Description
coll Array | Map | List | Set | Object | string | null
Source:
Returns:
Type
boolean
Example
isEmpty(list());
// => true

isEven(x) → {boolean}

isEven() returns true if x is even
Parameters:
Name Type Description
x number
Source:
Returns:
Type
boolean
Example
isEven(2);
// => true

isEven(null);
throws error

isEvery(pred, coll) → {boolean}

returns true if pred(x) is true for every x in coll, otherwise false
Parameters:
Name Type Description
pred function
coll Array | Map | List | Set | Object | string | null
Source:
Returns:
Type
boolean
Example
isEvery(isEven, [2, 4, 6]);
// => true

isEvery(isEven, [1, 2, 3]);
// => false

isFalse(x) → {boolean}

returns true if x is false, false otherwise
Parameters:
Name Type Description
x *
Source:
Returns:
Type
boolean
Example
isFalse(1 > 0);
// => false

isFloat(x) → {boolean}

returns true if x is a number
Parameters:
Name Type Description
x *
Source:
Returns:
Type
boolean
Example
isFloat(1);
// => true

isFloat("1");
// => false

isFloat(+"1");
// => true

isFn(x) → {boolean}

returns true if x is a function
Parameters:
Name Type Description
x *
Source:
Returns:
Type
boolean
Example
isFn(() => 1 + 1);
// => true

isFn(isNil);
// => true

isFn(1);
// => false

isInstance(c, x) → {boolean}

checks if x is an instance of c
Parameters:
Name Type Description
c Class
x *
Source:
Returns:
Type
boolean
Example
isInstance(String, "hello");
// => true

isInstance(Number, 5);
// => true

isInstance(Number, "5");
// => false

isInteger(x) → {boolean}

returns true if x is an integer
Parameters:
Name Type Description
x *
Source:
Returns:
Type
boolean
Example
isInteger(1);
// => true

isInteger(1.0);
// => true

isInteger(3.4);
// => false

isList(x) → {boolean}

checks if x is a List
Parameters:
Name Type Description
x *
Source:
Returns:
isList(new List(1, 2, 3)); // => true isList("hello"); // => false
Type
boolean

isMap(x) → {boolean}

returns true if x is a Map
Parameters:
Name Type Description
x *
Source:
Returns:
Type
boolean
Example
isMap([]);
// => false

isMap(new Map());
// => true

isMap({});
// => false

isNeg(x) → {boolean}

returns true if x is less than zero, false otherwise
Parameters:
Name Type Description
x *
Source:
Returns:
Type
boolean
Example
isNeg(-5);
// => true

isNotAny(pred, coll) → {boolean}

returns false if pred(x) is true for any x in coll, otherwise true
Parameters:
Name Type Description
pred function
coll Array | Map | List | Set | Object | string | null
Source:
Returns:
Type
boolean
Example
isNotAny(isOdd, [2, 4, 6]);
// => true

isNotEvery(pred, coll) → {boolean}

returns false if pred(x) is true for every x in coll, otherwise true
Parameters:
Name Type Description
pred function
coll Array | Map | List | Set | Object | string | null
Source:
Returns:
Type
boolean
Example
isNotEvery(isEven, [2, 4, 6]);
// => false

isNotEvery(isEven, [1, 2, 3]);
// => true

isNumber(x) → {boolean}

returns true if x is a number
Parameters:
Name Type Description
x *
Source:
Returns:
Type
boolean
Example
isNumber(1);
// => true

isNumber("1");
// => false

isNumber(+"1");
// => true

isObject(x) → {boolean}

returns true if x is an Object
Parameters:
Name Type Description
x *
Source:
Returns:
Type
boolean
Example
isObject([]);
// => false

isObject(list());
// => false

isObject({a: 2});
// => true

isOdd(x) → {boolean}

returns true if x is odd
Parameters:
Name Type Description
x number
Source:
Returns:
Type
boolean
Example
isOdd(3);
// => true

isOdd(null);
throws error

isPos(x) → {boolean}

returns true if x is greater than zero, false otherwise
Parameters:
Name Type Description
x *
Source:
Returns:
Type
boolean
Example
isPos(5);

// => true

isReduced(x) → {boolean}

returns true if x is the result of a call to reduced
Parameters:
Name Type Description
x function
Source:
Returns:
Type
boolean
Example
isReduced("foo");
// => false

isReduced(reduced("foo"));
// => true

isSeqable(x) → {boolean}

returns true if the seq function is supported for x
Parameters:
Name Type Description
x Array | List | Map | Set | Object | string | null
Source:
Returns:
Type
boolean
Example
isSeqable("hello");
// => true

isSet(x) → {boolean}

returns true if x is a Set
Parameters:
Name Type Description
x *
Source:
Returns:
Type
boolean
Example
isSet("abc");
false

isSet({});
false

isSet(set());
true

isSome(x) → {boolean}

returns true if x is not null or undefined, false otherwise
Parameters:
Name Type Description
x *
Source:
Returns:
Type
boolean
Example
isSome(1 < 5);
// => true

isString(x) → {boolean}

returns true if x is a string
Parameters:
Name Type Description
x *
Source:
Returns:
Type
boolean
Example
isString(5);
// => false

isString(true);
// => false

isTrue(x) → {boolean}

returns true if x is true, false otherwise
Parameters:
Name Type Description
x *
Source:
Returns:
Type
boolean
Example
isTrue(1 > 0);
// => true

isVector(x) → {boolean}

checks if x is an array
Parameters:
Name Type Description
x *
Source:
Returns:
Type
boolean
Example
isVector([1, 2, 3]);
// => true

isVector("hello");
// => false

isZero(x) → {boolean}

returns true if x is zero, false otherwise
Parameters:
Name Type Description
x *
Source:
Returns:
Type
boolean
Example
isZero(3);
// => false

itContains(coll) → {boolean}

returns true if key is present in the given collection, otherwise false. For arrays the key is the index.
Parameters:
Name Type Description
coll Array | Map | Set | List | Object
Source:
Returns:
Type
boolean
Example
itContains({name: "George", salary: "Biscuits"}, "name");
// => true

iterate(f, x) → {LazyIterable}

returns a lazy sequence of x, f(x), f(f(x)) etc
Parameters:
Name Type Description
f function
x number
Source:
Returns:
Type
LazyIterable
Example
[...take(3, iterate(inc, 5))];
// => [5, 6, 7]

[...take(10, iterate(partial(plus, 2), 0))];
// => [0,  2,  4,  6,  8, 10, 12, 14, 16, 18]

[...take(20, iterate(partial(plus, 2), 0))];
// => [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38]

var powersOfTwo = iterate(partial(multiply, 2), 1);
nth(powersOfTwo, 10);
// => 1024

[...take(10, powersOfTwo)];
// => [1,  2, 4, 8, 16, 32, 64, 128, 256, 512]

var fib = map(first, iterate(([a, b]) => [b, a + b], [0, 1]));
[...take(10, fib)];
// => [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]

keep(pred, coll) → {LazyIterable}

returns a lazy sequence of the non-nil results of f(item)
Parameters:
Name Type Description
pred function
coll Array | Map | List | Set | Object | string | null
Source:
Returns:
Type
LazyIterable
Example
[...keep(isEven, range(1, 10))];
// => [false, true, false, true, false, true, false, true, false]

keys(x) → {Array|null}

keys() returns all keys from a collection
Parameters:
Name Type Description
x Array | Map | List | Set | Object | string | null
Source:
Returns:
Type
Array | null
Example
keys({a: 1, b: 2, c: 3});
// => ["a", "b", "c"]

keys({});
// => null

keys(null);
// => null

last(coll) → {*}

returns the last item in a collection
Parameters:
Name Type Description
coll Array | List | Map | Set | Object | string | null
Source:
Returns:
Type
*
Example
last([1, 2, 3, 4, 5]);
// => 5

last({one: 1, two: 2, three: 3});
// => ["three", 3]

lett(bindings, f) → {*}

groups variables in a single scope
Parameters:
Name Type Description
bindings Array
f function
Source:
Returns:
Type
*
Example
lett([["x", 3], ["y", 4], ["z", 55]], (xs) => {
  return (xs.x * xs.y) + xs.z;
});

list(…args) → {List}

creates a new List containing args
Parameters:
Name Type Attributes Description
args * <repeatable>
Source:
Returns:
Type
List
Example
list("a", "b", "c");
// => List(3) ["a", "b", "c"]

list(1, 2, 3);
// => List(3) [1, 2, 3]

lt(xs) → {boolean}

less than (<) returns true if numbers are in decreasing order, otherwise false
Parameters:
Name Type Description
xs number
Source:
Returns:
Type
boolean
Example
lt(1, 2);
// => true

lt(2, 1);
// => false

lt(2, 3, 4, 5, 6);
// => true

map(f, colls) → {LazyIterable}

applies a given function to each element of a collection
Parameters:
Name Type Description
f function
colls Array | List | Map | Set | Object | string | null
Source:
Returns:
Type
LazyIterable
Example
[...map(inc, [1, 2, 3, 4, 5])];
// => [2, 3, 4, 5, 6]

[...map(last, {x: 1, y: 2, z: 3})];
// => [1, 2, 3]

mapIndexed(f, coll) → {Array}

returns an array of the result of applying f to 0 and the first item of coll, followed by applying f to 1 and the second item in the coll etc
Parameters:
Name Type Description
f function
coll Array | List | Map | Set | Object | string | null
Source:
Returns:
Type
Array
Example
mapIndexed((index, item) => [index, item], "foobar");
=> [
     [0, "f"],
     [1, "o"],
     [2, "o"],
     [3, "b"],
     [4, "a"],
     [5, "r"],
   ];

mapcat(f, …colls) → {LazyIterable}

returns a LazyIterable of applying concat to the result of applying map to f and colls
Parameters:
Name Type Attributes Description
f function
colls Array <repeatable>
Source:
Returns:
Type
LazyIterable
Example
[...mapcat(reverse, [[3, 2, 1, 0], [6, 5, 4], [9, 8, 7]])];
// => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

[...mapcat(list, ["a", "b", "c"], [1, 2, 3])];
// => ["a", 1, "b", 2, "c", 3]

mapv(args) → {Array}

returns the results of map() in an array rather than a lazy sequence
Parameters:
Name Type Description
args function
Array | List | Map | Set | Object | string | null
Source:
Returns:
Type
Array
Example
mapv(inc, [1, 2, 3, 4, 5]);
// => [2, 3, 4, 5, 6]

max(…args) → {number}

Returns the greatest of the numbers
Parameters:
Name Type Attributes Description
args number <repeatable>
Source:
Returns:
Type
number
Example
max(1, 2, 3, 4, 5);
// => 5

apply(max, [1, 2, 3, 4, 3]);
// => 4

merge(args) → {Array|Map|Set|List|Object}

returns an object that consists of the rest of the maps conjed onto the first
Parameters:
Name Type Description
args Array | Map | Set | List | Object | string | null
Source:
Returns:
Type
Array | Map | Set | List | Object
Example
merge({a: 1, b: 2, c: 3}, {b: 9, d: 4});
// => { a: 1, b: 9, c: 3, d: 4 }

min(…args) → {number}

Returns the least of the numbers
Parameters:
Name Type Attributes Description
args number <repeatable>
Source:
Returns:
Type
number
Example
min(1, 2, 3, 4, 5);
// => 1

min(5, 4, 3, 2, 1);
// => 1

minus(…xs) → {number}

returns the subtraction of numbers
Parameters:
Name Type Attributes Description
xs number <repeatable>
Source:
Returns:
Type
number
Example
minus(5, 1, 2);
// => 2

multiply(xs) → {number}

returns the product of numbers
Parameters:
Name Type Description
xs number
Source:
Returns:
Type
number
Example
multiply();
// => 1

multiply(6);
// => 6

multiply(2, 3);
// => 6

multiply(2, 3, 4);
// => 24

mutAssoc(coll, key, value) → {Array}

MUTATOR: adds a value to a structure by mutating the original
Parameters:
Name Type Description
coll Array | Map | Object
key number | string
value *
Source:
Returns:
Type
Array
Example
var arrData = [1, 2, 5, 6, 8, 9];
mutAssoc(someData, 0, 77);
// => [77, 2, 5, 6, 8, 9]

mutAssocIn(coll) → {Array}

MUTATOR: associates a value in a nested structure by mutating value
Parameters:
Name Type Description
coll Array | May | object
Source:
Returns:
Type
Array
Example
var pets = [
  { name: "George", age: 12 },
  { name: "Lola", age: 11 },
];
mutAssocIn(pets, [0, "age"], 13);
pets
// => [
//      { name: "George", age: 13 },
//      { name: "Lola", age: 11 },
//    ];

mutConj(xs) → {Set|Array|List|Map|Object}

MUTATOR: mutConj(oin) adds to a structure by mutation. The position of the addition depends on the structure type
Parameters:
Name Type Description
xs Set | Array | List | Map | Object
*
Source:
Returns:
Type
Set | Array | List | Map | Object
Example
mutConj([1, 2, 3], 4);
// => [1, 2, 3, 4]

mutConj({name: "George", coat: "Tabby"}, {age: 12, nationality: "British"})
// => {name: "George", coat: "Tabby", age: 12, nationality: "British"}

mutDisj(set) → {Set}

MUTATOR: removes item(s) from a set via mutation
Parameters:
Name Type Description
set Set
Source:
Returns:
Type
Set
Example
var disjSet = new Set(["a", "b", "c"]);
mutDisj(disjSet, "b");
// => Set(2) { "a", "c" }

mutDissoc(object, …keys) → {Object}

MUTATOR: removes item(s) from an object by key name
Parameters:
Name Type Attributes Description
object Object
keys string <repeatable>
Source:
Returns:
Type
Object
Example
var dissocObj = {name: "George", salary: "Biscuits"};
mutDissoc(dissocObj, "name", "salary");
// => {}
dissocObj
// => {}

mutReset(atom) → {*}

MUTATOR: resets the value stored in an atom
Parameters:
Name Type Description
atom Array | Map | Set | Object | string | null
Source:
Returns:
Type
*
Example
var myAtom = atom(0);
mutSwap(myAtom, inc);
deref(myAtom);
// => 1

mutReset(myAtom, 0);
deref(myAtom);
// => 0

mutSwap(atom, f, …args) → {*}

MUTATOR: automatically changes the value of an existing atom by applying f and returns the new value
Parameters:
Name Type Attributes Description
atom Atom
f function
args * <repeatable>
Source:
Returns:
Type
*
Example
var myAtom = atom(0);
mutSwap(myAtom, inc);
// => 1

mutUpdate(coll) → {Array|Map|Object}

MUTATOR: updates a collection with a value updated by f
Parameters:
Name Type Description
coll Array | Map | Object
Source:
Returns:
Type
Array | Map | Object
Example
var pet = {name: "George", age: 11};
mutUpdate(pet, "age", inc);
pet
// => {name: 'George', age: 12}

name(symbol) → {string}

returns the name of a Symbol
Parameters:
Name Type Description
symbol Symbol
Source:
Returns:
Type
string
Example
name(symbol("foo"));
// => "foo"

not(x) → {boolean}

returns true if x is logical false, false otherwise
Parameters:
Name Type Description
x *
Source:
Returns:
Type
boolean
Example
not(true);
// => false

notEq(x, y, …args) → {boolean}

the same as not(eq(x, y))
Parameters:
Name Type Attributes Description
x *
y *
args * <repeatable>
Source:
Returns:
Type
boolean
Example
notEq(1);
// => false

notEq(1, 2);
// => true

notEq([1, 2], [3, 4]);
// => true

nth(coll) → {*}

returns the value at the index
Parameters:
Name Type Description
coll Array | List | string
Source:
Returns:
Type
*
Example
nth(["a", "b", "c", "d"], 0);
// => "a"

or(…args) → {*}

returns the first argument that is truthy or the last argument if all arguments are falsy
Parameters:
Name Type Attributes Description
args * <repeatable>
Source:
Returns:
Type
*
Example
or(true, false, false);
// => true

or(null, null);
// => null

or(false, 42);
// => 42

partial(f, …xs) → {function}

takes a function f and fewer than normal arguments to f. It returns a fn that takes a variable number of additional args. When called, the returned function calls f with args plus additional args
Parameters:
Name Type Attributes Description
f function
xs * <repeatable>
Source:
Returns:
Type
function
Example
var hundredPlus = partial(plus, 100);
hundredPlus(5);
// => 105

partition(n, args) → {LazyIterable}

returns a lazy sequence of n items each at offsets step apart
Parameters:
Name Type Description
n number
args Array | Map | Set | Object | List | string | null
Source:
Returns:
Type
LazyIterable
Example
[...partition(4, range(20))];
// => [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15], [16, 17, 18, 19]]

partitionAll(n, args) → {Array}

returns a lazy sequence of arrays like partition but may include partitions with fewer than n items at the end
Parameters:
Name Type Description
n number
args Array | List | Map | Set | Object | string | null
Source:
Returns:
Type
Array
Example
[...partitionAll(4, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])];
// => [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9]]

plus(…xs) → {number}

returns the sum of numbers
Parameters:
Name Type Attributes Description
xs number <repeatable>
Source:
Returns:
Type
number
Example
plus(1, 2, 3);
// => 6

prStr(…xs) → {string}

turns a collection into a string and returns it
Parameters:
Name Type Attributes Description
xs * <repeatable>
Source:
Returns:
Type
string
Example
prStr([1, 2, 3, 4, 5]);
// => "[1,2,3,4,5]"

prStr({name: "George", salary: "Biscuits"});
// => "{"name":"George","salary":"Biscuits"}"

println(args) → {undefined}

a wrapper for console.log()
Parameters:
Name Type Description
args *
Source:
Returns:
Type
undefined
Example
println("Hello", "world");
(out) Hello world
// => undefined

prn(…xs) → {undefined}

turns a collection into a string and prints to console returns undefined
Parameters:
Name Type Attributes Description
xs * <repeatable>
Source:
Returns:
Type
undefined
Example
prn([1, 2, 3, 4, 5]);
(out) "[1,2,3,4,5]"
// => undefined

prn({name: "George", salary: "Biscuits"});
(out) "{"name":"George","salary":"Biscuits"}"
// => undefined

quot(a)

returns the quotient of dividing numerator by denominator
Parameters:
Name Type Description
a number
Source:
Returns:
{number
Example
quot(10, 3);
// => 3

quot(11, 3);
// => 3

quot(12, 3);
// => 4

randInt(n) → {number}

randInt() returns a random integer between 0 and n
Parameters:
Name Type Description
n number
Source:
Returns:
Type
number
Example
randInt(30);
// => 27

randInt(30);
// => 3

range(begin, end, step) → {LazyIterable}

returns a lazy sequence of numbers from start to end
Parameters:
Name Type Description
begin number
end number
step number
Source:
Returns:
Type
LazyIterable
Example
[...range(10)];
// => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

[...range(-5, 5)];
// => [-5, -4, -3, -2, -1, 0,  1,  2,  3,  4]

reSeq(pattern, string) → {LazyIterable}

returns a lazy sequence of successive matches of pattern in a string
Parameters:
Name Type Description
pattern RegExp
string string
Source:
Returns:
Type
LazyIterable
Example
[...reSeq(/\d/g, "test 5.9.2")];
// => ["5", "9", "2"]

[...reSeq(/\w+/g, "this is the story all about how")];
// => ["this", "is", "the",  "story", "all",  "about", "how"]

[...reSeq(/(\S+):(\d+)/g, " RX pkts:18 err:5 drop:48")];
// => [["pkts:18", "pkts", "18"], ["err:5", "err", "5"], ["drop:48", "drop", "48"]]

reduce(f) → {Array|List|Map|Set|Object|string}

iterates over a collection and applies a function to each element, returning a single result
Parameters:
Name Type Description
f function
Source:
Returns:
Type
Array | List | Map | Set | Object | string
Example
reduce(plus, [1, 2, 3, 4, 5]);
// => 15

reduce(plus, [1]);
// => 1

reduced(x) → {*}

wraps x so that reduce will terminate with the value x
Parameters:
Name Type Description
x *
Source:
Returns:
Type
*
Example
reduce((a, b) => {
  if ((a + b) > 20) {
    return reduced("Done early!");
  } else {
    return a + b;
  }
}, range(10));
// => "Done early!"

reductions(f, init, coll) → {LazyIterable}

returns a lazy sequence of the intermediate values of the reduction
Parameters:
Name Type Description
f function
init Array | List
coll Array | List
Source:
Returns:
Type
LazyIterable
Example
[...reductions(plus, [1, 2, 3, 4, 5])];
// => [1, 3, 6, 10, 15]

[...reductions(conj, [], list(1, 2, 3))];
// => [[], [1], [1, 2], [1, 2, 3]]

remove(predicate, coll) → {LazyIterable}

returns a lazy sequence of the items in coll for which pred(item) returns false
Parameters:
Name Type Description
predicate function check
coll Array | List | Map | Set | Object | string | null
Source:
Returns:
[...remove(isEven, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])]; // => [1, 3, 5, 7, 9]
Type
LazyIterable

repeat(…args) → {LazyIterable}

returns a lazy sequence of args
Parameters:
Name Type Attributes Description
args * <repeatable>
Source:
Returns:
Type
LazyIterable
Example
[...repeat(5, "x")];
// => ["x", "x", "x", "x", "x"]

repeatedly(n) → {function|LazyIterable}

takes a function of no args and returns it with n calls to it
Parameters:
Name Type Description
n number
Source:
Returns:
  • Type
    function
  • Type
    LazyIterable
Example
[...repeatedly(5, () => randInt(11))];
// => [7, 7, 7, 6, 4]

replace(coll1, coll2) → {*}

turns collection with any elements equal to a key in coll1 replaced with the corresponding val in coll1
Parameters:
Name Type Description
coll1 *
coll2 *
Source:
Returns:
Type
*
Example
replace(["zeroth", "first", "second", "third", "fourth"], [0, 2, 4, 0])
// => ["zeroth", "second", "fourth", "zeroth"]

rest(coll) → {LazyIterable}

returns a LazyIterable collection containing a possibly empty seq of the items after the first
Parameters:
Name Type Description
coll Array | List | Map | Set | Object | string | null
Source:
Returns:
Type
LazyIterable
Example
[...rest([1, 2, 3])];
// => [2, 3]

[...rest(null)];
// => []

reverse(coll) → {Array}

returns an array with items in reverse order
Parameters:
Name Type Description
coll Array | Map | Set | Object | string | null
Source:
Returns:
Type
Array
Example
reverse([1, 2, 3]);
// => [3, 2, 1]

reverse("hello");
// => ["o", "l", "l", "e", "h"]

second(coll) → {*}

returns the second item of a collection
Parameters:
Name Type Description
coll Array | List | Map | Set | Object | string | null
Source:
Returns:
Type
*
Example
second([1, 2, 3]);
// => 2

selectKeys(coll, keys) → {Object}

returns a map containing only those entries in the map whose key is in keys
Parameters:
Name Type Description
coll Array | Map | Set | Object | List | string | null
keys Array
Source:
Returns:
Type
Object
Example
selectKeys({a: 1, b: 2}, ["a"]);
// => {a: 1}

seq(x) → {Array|null}

takes a collection and returns an iterable of that collection, or nil if it's empty.
Parameters:
Name Type Description
x *
Source:
Returns:
Type
Array | null
Example
seq([1, 2]);
// => [1, 2]

seq(null);
// => null

set(coll) → {*}

returns a set of the distinct elements of coll
Parameters:
Name Type Description
coll Array | Map | List | Object | string | null
Source:
Returns:
Type
*
Example
set([1, 2, 3, 4, 5]);
// => Set(5) { 1, 2, 3, 4, 5 }

set("abcd")
// => Set(4) { 'a', 'b', 'c', 'd' }

shuffle(coll) → {Array}

returns a random permutation of coll
Parameters:
Name Type Description
coll Array | List | Set | string
Source:
Returns:
Type
Array
Example
shuffle([1, 2, 3, 4]);
// => [2, 1, 3, 4]

some(pred, coll) → {*}

returns the first true value of pred(x) for any x in coll, otherwise null
Parameters:
Name Type Description
pred function
coll Array | Map | List | Set | Object | string | null
Source:
Returns:
Type
*
Example
some(isEven, [1, 2, 3, 4]);
// => true

sort(f, coll) → {Array}

returns a sorted sequence of the items in coll
Parameters:
Name Type Description
f function
coll Array | List | Set | string
Source:
Returns:
Type
Array
Example
sort([3, 4, 1, 2]);
// => [1, 2, 3, 4]

sort((a, b) => b - a, [3, 4, 1, 2]);
// => [4, 3, 2, 1]

splitAt(n) → {Array}

returns an array of [take(n, coll), drop(n, coll)]
Parameters:
Name Type Description
n Array | Map | List | Set | Object | string | null
Source:
Returns:
Type
Array
Example
splitAt(2, [1, 2, 3, 4, 5]);
// => [[1, 2], [3, 4, 5]]

splitWith(pred, coll) → {Array}

returns an array of [takeWhile(pred, coll), dropWhile(pred, coll)]
Parameters:
Name Type Description
pred function
coll Array | Map | List | Set | Object | string | null
Source:
Returns:
Type
Array
Example
splitWith(isOdd, [1, 3, 5, 6, 7, 9]);
// => [[1, 3, 5], [6, 7, 9]]

str(…xs) → {string}

returns a string for single values and a concatenation of multiple values
Parameters:
Name Type Attributes Description
xs * <repeatable>
Source:
Returns:
Type
string
Example
str(1);
// => "1"

str(1, 2, 3);
// => "123"

subvec(array, start, end) → {Array}

returns an array of the items in an array from start to end
Parameters:
Name Type Description
array Array
start number
end number
Source:
Returns:
Type
Array
Example
subvec([1, 2, 3, 4, 5, 6, 7], 2);
// => [3, 4, 5, 6, 7]

subvec([1, 2, 3, 4, 5, 6, 7], 2, 4);
// => [3, 4]

symbol(name) → {Symbol}

returns a Symbol with the given name
Parameters:
Name Type Description
name string
Source:
Returns:
Type
Symbol
Example
symbol("foo");
Symbol(foo)

take(n, coll) → {LazyIterable}

returns a lazy sequence of the first n items in coll, or all items if there are fewer than n
Parameters:
Name Type Description
n number
coll Array | Map | List | Set | Object | string | null
Source:
Returns:
Type
LazyIterable
Example
[...take(3, [1, 2, 3, 4, 5, 6])];
// => [1, 2, 3]

[...take(3, [1, 2])];
// => [1, 2]

takeNth(n, coll) → {LazyIterable}

returns a lazy sequence of every nth item in coll
Parameters:
Name Type Description
n number
coll Array | Map | List | Set | Object | string
Source:
Returns:
Type
LazyIterable
Example
[...takeNth(2, range(10))];
// => [0, 2, 4, 6, 8]

takeWhile(pred, coll) → {LazyIterable}

returns a lazy sequence of successive items from coll while pred(item) returns true
Parameters:
Name Type Description
pred function
coll Array | Map | List | Set | Object | string | null
Source:
Returns:
Type
LazyIterable
Example
[...takeWhile(isNeg, [-2, -1, 0, 1, 2, 3])];
// => [-2, -1]

tf(x, …fns) → {*}

thread first threads x through the fns. Inserts x as the second item in the first function. It will do the same for following functions.
Parameters:
Name Type Attributes Description
x *
fns function <repeatable>
Source:
Returns:
Type
*
Example
tf("3", parseInt);
// => 3

tl(x, …fns) → {*}

thread last threads x through the fns. Inserts x as the last item in the first function. It will do the same for following functions
Parameters:
Name Type Attributes Description
x *
fns function <repeatable>
Source:
Returns:
Type
*
Example
tl("3", parseInt);
// => 3

update(coll, key, f, …args) → {Array|Map|Object}

returns a new structure with a value updated by f
Parameters:
Name Type Attributes Description
coll Array | Map | Object
key *
f function
args * <repeatable>
Source:
Returns:
Type
Array | Map | Object
Example
update([1, 2, 3], 0, inc);
// => [2, 2, 3]

update([], 0, function(item) { return str("foo", item); });
// => ["foo"]

updateIn(coll, path, f, …args) → {Array|Map|List|Set|Object}

updates a value in a nested structure
Parameters:
Name Type Attributes Description
coll Array | Map | List | Set | Object
path Array
f function
args * <repeatable>
Source:
Returns:
Type
Array | Map | List | Set | Object
Example
var pets = [{name: "George", age: 11}, {name: "Lola", age: 10}];
updateIn(pets, [1, "age"], inc);
// => [{name: "George", age: 11}, {name: "Lola", age: 11}]

vals(x) → {Array|null}

returns all values from an object
Parameters:
Name Type Description
x Array | Map | List | Set | Object | string | null
Source:
Returns:
Type
Array | null
Example
vals({a: 1, b: 2, c: 3});
// => [1, 2, 3]

vals({});
// => null

vals(null);
// => null

vec(coll) → {Array}

creates a new array containing iterable of coll
Parameters:
Name Type Description
coll Array | Map | List | Set | Object | string | null
Source:
Returns:
Type
Array
Example
vec(null);
[]

vec({a: 1, b: 2, c: 3});
[["a", 1], ["b", 2], ["c", 3]]

vector(…args) → {Array}

returns a new array containing args
Parameters:
Name Type Attributes Description
args * <repeatable>
Source:
Returns:
Type
Array
Example
vector();
// => []

vector(1, 2, 3);
// => [1, 2, 3]

zipmap(k, v) → {Object}

returns an object with keys mapped to corresponding values
Parameters:
Name Type Description
k Array
v Array
Source:
Returns:
Type
Object
Example
zipmap(["a", "b", "c"], [1, 2, 3]);
// => {a: 1, b: 2, c: 3}