Module: prelude

prelude

This is the rq standard library as implemented in Javascript.

Note that the examples in this file are doctests. Any line with the format:

<input> → <process> <args>* → <output>

...will be verified as part of the build.

Methods

staticmodule:prelude.add(other)

Adds something to each element of the input stream.

This:
  • rq.Context
Name Type Description
other *

The addend.

Example
1 2 3 → add 4 → 5 6 7
"a" "b" "c" → add "d" → "ad" "bd" "cd"

staticmodule:prelude.all(predicate)

Checks if predicate returns truthy for all elements of the input stream. Iteration is stopped once predicate returns falsey. The predicate is invoked with two arguments: (value, index).

This:
  • rq.Context
Name Type Default Description
predicate function _.identity optional

The function invoked per iteration.

Example
true 1 null "yes" → all (Boolean) → false
// With index
1 2 3 → all (x, i) => { i + 1 == x } → true
// The `matches` iteratee shorthand.
{"u": "b", "g": 36, "a": false} {"u": "f", "g": 40, "a": false} → all {"u": "b", "a": false} → false
// The `matchesProperty` iteratee shorthand.
{"u": "b", "g": 36, "a": false} {"u": "f", "g": 40, "a": false} → all ["a", false] → true
// The `property` iteratee shorthand.
{"u": "b", "g": 36, "a": false} {"u": "f", "g": 40, "a": false} → all "a" → false

staticmodule:prelude.any(predicate)

Checks if predicate returns truthy for any element of the input stream. Iteration is stopped once predicate returns truthy. The predicate is invoked with two arguments: (value, index).

This:
  • rq.Context
Name Type Default Description
predicate function _.identity optional

The function invoked per iteration.

Example
null 0 "yes" false → any (Boolean) → true
// With index
5 1 8 → any (x, i) => { i == x } → true
// The `matches` iteratee shorthand.
{"u": "b", "a": true} {"u": "f", "a": false} → any {"u": "b", "a": false} → false
// The `matchesProperty` iteratee shorthand.
{"u": "b", "a": true} {"u": "f", "a": false} → any ["a", false] → true
// The `property` iteratee shorthand.
{"u": "b", "a": true} {"u": "f", "a": false} → any "a" → true

staticmodule:prelude.assign(sources)

Assigns own enumerable string keyed properties of source objects to the destination object. Source objects are applied from left to right. Subsequent sources overwrite property assignments of previous sources.

Note: This method mutates object and is loosely based on Object.assign.

This:
  • rq.Context
Name Type Description
sources Object optional repeatable

The source objects..

Example
{"a": 0, "b": 2} → assign {"a": 1, "c": 3} → {"a": 1, "b": 2, "c": 3}

staticmodule:prelude.at(object, paths)

Creates an array of values corresponding to paths of object.

This:
  • rq.Context
Name Type Description
object Object

The object to iterate over.

paths string | Array.<string> optional repeatable

The property paths of elements to pick.

Example
{ "a": [{ "b": { "c": 3 } }, 4] } → at "a[0].b.c" → 3
{ "a": [{ "b": { "c": 3 } }, 4] } → at "a[0].b.c" "a[1]" → [3, 4]

staticmodule:prelude.camelCase()

Converts each input string to camel case.

This:
  • rq.Context
Example
"Foo Bar"     → camelCase → "fooBar"
"--foo-bar--" → camelCase → "fooBar"
"__FOO_BAR__" → camelCase → "fooBar"

staticmodule:prelude.capitalize()

Converts each input strings first letter to upper case and the remaining to lower case.

This:
  • rq.Context
Example
"FRED" → capitalize → "Fred"

staticmodule:prelude.ceil(precision)

Computes the ceiling of each element of the input stream rounded up to precision.

This:
  • rq.Context
Name Type Default Description
precision number 0 optional

The precision to round up to.

Example
4.006 → ceil    → 5
6.004 → ceil  2 → 6.01
6040  → ceil -2 → 6100

staticmodule:prelude.chunk(size)

Creates a stream of elements split into groups the length of size. If the input stream can't be split evenly, the final chunk will be the remaining elements.

This:
  • rq.Context
Name Type Default Description
size number 1 optional

The length of each chunk

Example
"a" "b" "c" "d" → chunk    → ["a"] ["b"] ["c"] ["d"]
"a" "b" "c" "d" → chunk  2 → ["a", "b"] ["c", "d"]
"a" "b" "c" "d" → chunk  3 → ["a", "b", "c"] ["d"]

// Edge cases
"a" "b" "c" "d" → chunk -1 → (empty)
"a" "b" "c" "d" → chunk  0 → (empty)

staticmodule:prelude.collect()

Collects all of the values from the input stream into an array.

This:
  • rq.Context
Example
true [] 1 → collect → [true, [], 1]

staticmodule:prelude.compact()

Creates a stream with all falsey values removed. The values false, null, 0, "", undefined, and NaN are falsey.

This:
  • rq.Context
Example
0 1 false 2 "" 3 → compact → 1 2 3

staticmodule:prelude.concat()

Creates a new stream concatenating all input arrays.

This:
  • rq.Context
Example
[1] 2 [3] [[4]] → concat → [1, 2, 3, [4]]

staticmodule:prelude.conformsTo(source)

Checks if input objects conform to source by invoking the predicate properties of source with the corresponding property values of each input object.

Note: This method is equivalent to conforms when source is partially applied.

This:
  • rq.Context
Name Type Description
source Object

The object of property predicates to conform to.

Example
{"a": 1, "b": 2 } → conformsTo {"b": (n)=>{ n > 1 } } → true (not tested)
{"a": 1, "b": 2 } → conformsTo {"b": (n)=>{ n > 2 } } → false (not tested)

staticmodule:prelude.count()

Counts the number of input elements.

This:
  • rq.Context
Example
6.1 4.2 6.3         → count → 3
"one" "two" "three" → count → 3

staticmodule:prelude.countBy(iteratee)

Creates an object composed of keys generated from the results of running each element of the input stream thru iteratee. The corresponding value of each key is the number of times the key was returned by iteratee. The iteratee is invoked with one argument: (value).

This:
  • rq.Context
Name Type Default Description
iteratee function _.identity optional

The iteratee to transform keys.

Example
6.1 4.2 6.3         → countBy (Math.floor) → {"4": 1, "6": 2}
"one" "two" "three" → countBy "length"     → {"3": 2, "5": 1}

staticmodule:prelude.deburr()

Deburrs each input string by converting Latin-1 Supplement#Character_table) and Latin Extended-A letters to basic Latin letters and removing combining diacritical marks.

This:
  • rq.Context
Example
"déjà vu" → deburr → "deja vu"

staticmodule:prelude.defaults(sources)

Assigns own and inherited enumerable string keyed properties of source objects to the destination object for all destination properties that resolve to undefined. Source objects are applied from left to right. Once a property is set, additional values of the same property are ignored.

Note: This method mutates object.

This:
  • rq.Context
Name Type Description
sources Object optional repeatable

The source objects..

Example
{"a": 0, "b": 2} → defaults {"a": 1, "c": 3} → {"a": 0, "b": 2, "c": 3}

staticmodule:prelude.defaultsDeep(sources)

This method is like defaults except that it recursively assigns default properties.

Note: This method mutates object.

This:
  • rq.Context
Name Type Description
sources Object optional repeatable

The source objects..

Example
{ "a": { "b": 2 } } → defaultsDeep { "a": { "b": 1, "c": 3 } } → { "a": { "b": 2, "c": 3 } }

staticmodule:prelude.difference(values)

Creates a stream of values not included in the given array using SameValueZero for equality comparisons. The order of result values is determined by the order they occur in the input.

This:
  • rq.Context
Name Type Description
values Array optional

The values to exclude.

See:
  • without, xor
Example
2 1 → difference [2, 3] → 1

staticmodule:prelude.differenceBy(values, iteratee)

This method is like difference except that it accepts iteratee which is invoked for each element of the input and values to generate the criterion by which they're compared. Result values are chosen from the input stream. The iteratee is invoked with one argument: (value).

This:
  • rq.Context
Name Type Default Description
values Array optional

The values to exclude.

iteratee function _.identity optional

The iteratee invoked per element.

Example
2.1 1.2 → differenceBy [2.3, 3.4] (Math.floor) → 1.2
// The `property` iteratee shorthand.
{"x": 2} {"x": 1} → differenceBy [{"x": 1}] "x" → {"x": 2}

staticmodule:prelude.differenceWith(values, comparator)

This method is like difference except that it accepts comparator which is invoked to compare elements of the input to values. The comparator is invoked with two arguments: (inputVal, othVal).

This:
  • rq.Context
Name Type Description
values Array optional

The values to exclude.

comparator function optional

The comparator invoked per element.

Example
{"x": 1, "y": 2} {"x": 2, "y": 1} → differenceWith [{"x": 1, "y": 2}] (_.isEqual) → {"x": 2, "y": 1}

staticmodule:prelude.divide(other)

Divides each element of the input stream by something.

This:
  • rq.Context
Name Type Description
other *

The divisor.

Example
1 2 3 → divide 2 → 0.5 1 1.5

staticmodule:prelude.drop(n)

Creates a slice of the input stream with n elements dropped from the beginning.

This:
  • rq.Context
Name Type Default Description
n number 1 optional

The number of elements to drop.

Example
1 2 3 → drop   → 2 3
1 2 3 → drop 2 → 3
1 2 3 → drop 5 → (empty)
1 2 3 → drop 0 → 1 2 3

staticmodule:prelude.dropRight(n)

Creates a slice of the input stream with n elements dropped from the end.

This:
  • rq.Context
Name Type Default Description
n number 1 optional

The number of elements to drop.

Example
1 2 3 → dropRight   → 1 2
1 2 3 → dropRight 2 → 1
1 2 3 → dropRight 5 → (empty)
1 2 3 → dropRight 0 → 1 2 3

staticmodule:prelude.dropRightWhile(predicate)

Creates a slice of the input stream excluding elements dropped from the end. Elements are dropped until predicate returns falsey. The predicate is invoked with three arguments: (value, index, array).

This:
  • rq.Context
Name Type Default Description
predicate function _.identity optional

The function invoked per iteration.

Example
{"u": "b", "a": true} {"u": "f", "a": false} {"u": "p", "a": false} → dropRightWhile (o => !o.a) → {"u": "b", "a": true}
// The `matches` iteratee shorthand.
{"u": "b", "a": true} {"u": "f", "a": false} {"u": "p", "a": false} → dropRightWhile {"u": "p", "a": false} → {"u": "b", "a": true} {"u": "f", "a": false}
// The `matchesProperty` iteratee shorthand.
{"u": "b", "a": true} {"u": "f", "a": false} {"u": "p", "a": false} → dropRightWhile ["a", false] → {"u": "b", "a": true}
// The `property` iteratee shorthand.
{"u": "b", "a": true} {"u": "f", "a": false} {"u": "p", "a": false} → dropRightWhile "a" → {"u": "b", "a": true} {"u": "f", "a": false} {"u": "p", "a": false}

staticmodule:prelude.dropWhile(predicate)

Creates a slice of the input stream excluding elements dropped from the beginning. Elements are dropped until predicate returns falsey. The predicate is invoked with three arguments: (value, index, array).

This:
  • rq.Context
Name Type Default Description
predicate function _.identity optional

The function invoked per iteration.

Example
{"u": "b", "a": false} {"u": "f", "a": false} {"u": "p", "a": true} → dropWhile (o => !o.a) → {"u": "p", "a": true}
// The `matches` iteratee shorthand.
{"u": "b", "a": false} {"u": "f", "a": false} {"u": "p", "a": true} → dropWhile {"u": "b", "a": false} → {"u": "f", "a": false} {"u": "p", "a": true}
// The `matchesProperty` iteratee shorthand.
{"u": "b", "a": false} {"u": "f", "a": false} {"u": "p", "a": true} → dropWhile ["a", false] → {"u": "p", "a": true}
// The `property` iteratee shorthand.
{"u": "b", "a": false} {"u": "f", "a": false} {"u": "p", "a": true} → dropWhile "a" → {"u": "b", "a": false} {"u": "f", "a": false} {"u": "p", "a": true}

staticmodule:prelude.endsWith(target, position)

Checks if each input string ends with the given target string.

This:
  • rq.Context
Name Type Default Description
target string optional

The string to search for.

position number string.length optional

The position to search up to.

Example
"abc" → endsWith "c"   → true
"abc" → endsWith "b"   → false
"abc" → endsWith "b" 2 → true

staticmodule:prelude.eq(other)

Performs a SameValueZero comparison between two values to determine if they are equivalent.

This:
  • rq.Context
Name Type Description
other *

The other value to compare.

Example
2 3     → eq 2   → true false
"a" "b" → eq "a" → true false
{}      → eq {}  → false

staticmodule:prelude.escape()

Converts the characters "&", "<", ">", '"', and "'" in each input string to their corresponding HTML entities.

Note: No other characters are escaped. To escape additional characters use a third-party library like he.

Though the ">" character is escaped for symmetry, characters like ">" and "/" don't need escaping in HTML and have no special meaning unless they're part of a tag or unquoted attribute value. See Mathias Bynens's article (under "semi-related fun fact") for more details.

When working with HTML you should always quote attribute values to reduce XSS vectors.

This:
  • rq.Context
Example
"fred, barney, & pebbles" → escape → "fred, barney, &amp; pebbles"

staticmodule:prelude.escapeRegExp()

Escapes the RegExp special characters "^", "$", "\", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", and "|" in each input string.

This:
  • rq.Context
Example
"[lodash](https://lodash.com/)" → escapeRegExp → "\\[lodash\\]\\(https://lodash\\.com/\\)"

staticmodule:prelude.every(predicate)

Checks if predicate returns truthy for all elements of the input stream. Iteration is stopped once predicate returns falsey. The predicate is invoked with two arguments: (value, index).

This:
  • rq.Context
Name Type Default Description
predicate function _.identity optional

The function invoked per iteration.

Example
true 1 null "yes" → every (Boolean) → false
// With index
1 2 3 → every (x, i) => { i + 1 == x } → true
// The `matches` iteratee shorthand.
{"u": "b", "g": 36, "a": false} {"u": "f", "g": 40, "a": false} → every {"u": "b", "a": false} → false
// The `matchesProperty` iteratee shorthand.
{"u": "b", "g": 36, "a": false} {"u": "f", "g": 40, "a": false} → every ["a", false] → true
// The `property` iteratee shorthand.
{"u": "b", "g": 36, "a": false} {"u": "f", "g": 40, "a": false} → every "a" → false

staticmodule:prelude.fill(value, start, end)

Fills elements of the input stream with value from start up to, but not including, end.

This:
  • rq.Context
Name Type Default Description
value *

The value to fill the input stream with.

start number 0 optional

The start position.

end number array.length optional

The end position.

Example
4 6 8 10 → fill "*" 1 3 → 4 "*" "*" 10

staticmodule:prelude.filter(predicate)

Iterates over elements of the input stream, returning an array of all elements predicate returns truthy for. The predicate is invoked with two arguments: (value, index).

Note: Unlike remove, this method returns a new array.

This:
  • rq.Context
Name Type Default Description
predicate function _.identity optional

The function invoked per iteration.

See:
  • _.reject
Example
"a" "b"  "c"   → filter (s)=>{"a" === s}     → "a"
"a" "ab" "abc" → filter (s)=>{s.length == 2} → "ab"
"a" "ab" "abc" → filter (s, i)=>{i % 2 == 0} → "a" "abc"
{"u": "b", "g": 36, "a": true} {"u": "f", "g": 40, "a": false} → filter (o)=>{!o.a} → {"u": "f", "g": 40, "a": false}
// The `matches` iteratee shorthand.
{"u": "b", "g": 36, "a": true} {"u": "f", "g": 40, "a": false} → filter {"g": 36, "a": true} → {"u": "b", "g": 36, "a": true}
// The `matchesProperty` iteratee shorthand.
{"u": "b", "g": 36, "a": true} {"u": "f", "g": 40, "a": false} → filter ["a", false] → {"u": "f", "g": 40, "a": false}
// The `property` iteratee shorthand.
{"u": "b", "g": 36, "a": true} {"u": "f", "g": 40, "a": false} → filter "a" → {"u": "b", "g": 36, "a": true}

staticmodule:prelude.find(predicate)

Iterates over elements of the input stream, returning the first element predicate returns truthy for. The predicate is invoked with two arguments: (value, index).

This:
  • rq.Context
Name Type Default Description
predicate function _.identity optional

The function invoked per iteration.

Example
{"u": "b", "g": 36, "a": true} {"u": "f", "g": 40, "a": false} {"u": "p", "g": 1, "a": true} → find (o)=>{o.g < 40} → {"u": "b", "g": 36, "a": true}
// The `matches` iteratee shorthand.
{"u": "b", "g": 36, "a": true} {"u": "f", "g": 40, "a": false} {"u": "p", "g": 1, "a": true} → find {"g": 1, "a": true} → {"u": "p", "g": 1, "a": true}
// The `matchesProperty` iteratee shorthand.
{"u": "b", "g": 36, "a": true} {"u": "f", "g": 40, "a": false} {"u": "p", "g": 1, "a": true} → find ["a", false] → {"u": "f", "g": 40, "a": false}
// The `property` iteratee shorthand.
{"u": "b", "g": 36, "a": true} {"u": "f", "g": 40, "a": false} {"u": "p", "g": 1, "a": true} → find "a" → {"u": "b", "g": 36, "a": true}

staticmodule:prelude.findIndex(predicate, fromIndex)

This method is like find except that it returns the index of the first element predicate returns truthy for instead of the element itself.

This:
  • rq.Context
Name Type Default Description
predicate function _.identity optional

The function invoked per iteration.

fromIndex number 0 optional

The index to search from.

Example
{"u": "b", "a": false} {"u": "f", "a": false} {"u": "p", "a": true} → findIndex (o => o.u == 'b') → 0
// The `matches` iteratee shorthand.
{"u": "b", "a": false} {"u": "f", "a": false} {"u": "p", "a": true} → findIndex {"u": "f", "a": false} → 1
// The `matchesProperty` iteratee shorthand.
{"u": "b", "a": false} {"u": "f", "a": false} {"u": "p", "a": true} → findIndex ["a", false] → 0
// The `property` iteratee shorthand.
{"u": "b", "a": false} {"u": "f", "a": false} {"u": "p", "a": true} → findIndex "a" → 2

staticmodule:prelude.findKey(predicate)

This method is like find except that it returns the key of the first element predicate returns truthy for instead of the element itself.

This:
  • rq.Context
Name Type Default Description
predicate function _.identity optional

The function invoked per iteration.

Example
{"a": {"u": "b", "g": 36, "a": true}, "b": {"u": "f", "g": 40, "a": false}, "c": {"u": "p", "g": 1, "a": true}} → findKey (o)=>{o.g < 40} → "a"
// The `matches` iteratee shorthand.
{"a": {"u": "b", "g": 36, "a": true}, "b": {"u": "f", "g": 40, "a": false}, "c": {"u": "p", "g": 1, "a": true}} → findKey {"g": 1, "a": true} → "c"
// The `matchesProperty` iteratee shorthand.
{"a": {"u": "b", "g": 36, "a": true}, "b": {"u": "f", "g": 40, "a": false}, "c": {"u": "p", "g": 1, "a": true}} → findKey ["a", false] → "b"
// The `property` iteratee shorthand.
{"a": {"u": "b", "g": 36, "a": true}, "b": {"u": "f", "g": 40, "a": false}, "c": {"u": "p", "g": 1, "a": true}} → findKey "a" → "a"

staticmodule:prelude.findLast(predicate, fromIndex)

This method is like find except that it iterates over elements of the input stream from right to left.

This:
  • rq.Context
Name Type Default Description
predicate function _.identity optional

The function invoked per iteration.

fromIndex number collection.length-1 optional

The index to search from.

Example
1 2 3 4 → findLast (n)=>{n % 2 == 1} → 3

staticmodule:prelude.findLastIndex(predicate, fromIndex)

This method is like findIndex except that it iterates over elements of collection from right to left.

This:
  • rq.Context
Name Type Default Description
predicate function _.identity optional

The function invoked per iteration.

fromIndex number array.length-1 optional

The index to search from.

Example
{"u": "b", "a": true} {"u": "f", "a": false} {"u": "p", "a": false} → findLastIndex (o => o.u == 'p') → 2
// The `matches` iteratee shorthand.
{"u": "b", "a": true} {"u": "f", "a": false} {"u": "p", "a": false} → findLastIndex {"u": "b", "a": true} → 0
// The `matchesProperty` iteratee shorthand.
{"u": "b", "a": true} {"u": "f", "a": false} {"u": "p", "a": false} → findLastIndex ["a", false] → 2
// The `property` iteratee shorthand.
{"u": "b", "a": true} {"u": "f", "a": false} {"u": "p", "a": false} → findLastIndex "a" → 0

staticmodule:prelude.findLastKey(predicate)

This method is like findKey except that it iterates over elements of a collection in the opposite order.

This:
  • rq.Context
Name Type Default Description
predicate function _.identity optional

The function invoked per iteration.

Example
{"a": {"u": "b", "g": 36, "a": true}, "b": {"u": "f", "g": 40, "a": false}, "c": {"u": "p", "g": 1, "a": true}} → findLastKey (o)=>{o.g < 40} → "c"
// The `matches` iteratee shorthand.
{"a": {"u": "b", "g": 36, "a": true}, "b": {"u": "f", "g": 40, "a": false}, "c": {"u": "p", "g": 1, "a": true}} → findLastKey {"g": 1, "a": true} → "c"
// The `matchesProperty` iteratee shorthand.
{"a": {"u": "b", "g": 36, "a": true}, "b": {"u": "f", "g": 40, "a": false}, "c": {"u": "p", "g": 1, "a": true}} → findLastKey ["a", false] → "b"
// The `property` iteratee shorthand.
{"a": {"u": "b", "g": 36, "a": true}, "b": {"u": "f", "g": 40, "a": false}, "c": {"u": "p", "g": 1, "a": true}} → findLastKey "a" → "c"

staticmodule:prelude.flatMap(iteratee)

Creates a flattened array of values by running each element in the input stream thru iteratee and flattening the mapped results. The iteratee is invoked with three arguments: (value, index|key, collection).

This:
  • rq.Context
Name Type Default Description
iteratee function _.identity optional

The function invoked per iteration.

Example
1 2 → flatMap (n)=>{[n, n]} → 1 1 2 2

staticmodule:prelude.flatMapDeep(iteratee)

This method is like flatMap except that it recursively flattens the mapped results.

This:
  • rq.Context
Name Type Default Description
iteratee function _.identity optional

The function invoked per iteration.

Example
1 2 → flatMapDeep (n)=>{[[[n, n]]]} → 1 1 2 2

staticmodule:prelude.flatMapDepth(iteratee, depth)

This method is like flatMap except that it recursively flattens the mapped results up to depth times.

This:
  • rq.Context
Name Type Default Description
iteratee function _.identity optional

The function invoked per iteration.

depth number 1 optional

The maximum recursion depth.

Example
1 2 → flatMapDepth (n)=>{[[[n, n]]]} 2 → [1, 1] [2, 2]

staticmodule:prelude.flatten()

Flattens the input stream a single level deep.

This:
  • rq.Context
Example
1  [2, [3, [4]], 5] → flatten → 1 2 [3, [4]] 5

staticmodule:prelude.flattenDeep()

Recursively flattens the input stream.

This:
  • rq.Context
Example
1 [2, [3, [4]], 5] → flattenDeep → 1 2 3 4 5

staticmodule:prelude.flattenDepth(depth)

Recursively flatten the input stream up to depth times.

This:
  • rq.Context
Name Type Default Description
depth number 1 optional

The maximum recursion depth.

Example
1 [2, [3, [4]], 5] → flattenDepth 1 → 1 2 [3, [4]] 5
1 [2, [3, [4]], 5] → flattenDepth 2 → 1 2 3 [4] 5

staticmodule:prelude.floor(precision)

Computes the floor of each element of the input stream rounded down to precision.

This:
  • rq.Context
Name Type Default Description
precision number 0 optional

The precision to round down to.

Example
4.006 → floor    → 4
0.046 → floor  2 → 0.04
4060  → floor -2 → 4000

staticmodule:prelude.fromPairs()

The inverse of toPairs; this method returns an object composed from key-value pairs.

This:
  • rq.Context
Example
["a", 1] ["b", 2] → fromPairs → {"a": 1, "b": 2}

staticmodule:prelude.get(path, defaultValue)

Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.

This:
  • rq.Context
Name Type Description
path Array | string

The path of the property to get.

defaultValue * optional

The value returned for undefined resolved values.

Example
{ "a": [{ "b": { "c": 3 } }] } → get "a[0].b.c" → 3
{ "a": [{ "b": { "c": 3 } }] } → get ["a", "0", "b", "c"] → 3
{ "a": [{ "b": { "c": 3 } }] } → get "a.b.c" "default" → "default"

staticmodule:prelude.groupBy(iteratee)

Creates an object composed of keys generated from the results of running each element of the input stream thru iteratee. The order of grouped values is determined by the order they occur in the input stream. The corresponding value of each key is an array of elements responsible for generating the key. The iteratee is invoked with one argument: (value).

This:
  • rq.Context
Name Type Default Description
iteratee function _.identity optional

The iteratee to transform keys.

Example
6.1 4.2 6.3 → groupBy (Math.floor) → {"4": [4.2], "6": [6.1, 6.3]}
// The `property` iteratee shorthand.
"one" "two" "three" → groupBy "length" → {"3": ["one", "two"], "5": ["three"]}

staticmodule:prelude.gt(other)

Checks if each input value is greater than other.

This:
  • rq.Context
Name Type Description
other *

The other value to compare.

Example
1 2 3 → gt 2 → false false true

staticmodule:prelude.gte(other)

Checks if each input value is greater than or equal to other.

This:
  • rq.Context
Name Type Description
other *

The other value to compare.

Example
1 2 3 → gte 2 → false true true

staticmodule:prelude.has(path)

Checks if path is a direct property of object.

This:
  • rq.Context
Name Type Description
path Array | string

The path to check.

Example
{ "a": { "b": 2 } } → has "a" → true
{ "a": { "b": 2 } } → has "a.b" → true
{ "x": 3 }          → has "a" → false

staticmodule:prelude.head()

Gets the first element of the input stream.

This:
  • rq.Context
Example
1 2 3   → head → 1
(empty) → head → null

staticmodule:prelude.id()

Passes through all of the values it sees untouched.

This:
  • rq.Context
Example
{"a": 2, "b": 3} → id → {"a": 2, "b": 3}
true             → id → true

staticmodule:prelude.includes(value, fromIndex)

Checks if value is in the input stream. If the input stream is a string, it's checked for a substring of value, otherwise SameValueZero is used for equality comparisons. If fromIndex is negative, it's used as the offset from the end of the input stream.

This:
  • rq.Context
Name Type Default Description
value *

The value to search for.

fromIndex number 0 optional

The index to search from.

Example
1 2 3 → includes 1   → true
1 2 3 → includes 1 2 → false

staticmodule:prelude.indexOf(value, fromIndex)

Gets the index at which the first occurrence of value is found in the input stream using SameValueZero for equality comparisons. If fromIndex is negative, it's used as the offset from the end of the input stream.

This:
  • rq.Context
Name Type Default Description
value *

The value to search for.

fromIndex number 0 optional

The index to search from.

Example
1 2 1 2 → indexOf 2   → 1
// Search from the `fromIndex`.
1 2 1 2 → indexOf 2 2 → 3

staticmodule:prelude.initial()

Gets all but the last element of the input stream.

This:
  • rq.Context
Example
1 2 3 → initial → 1 2

staticmodule:prelude.intersection(values)

Creates a stream of unique values that are included in the given array using SameValueZero for equality comparisons. The order of result values is determined by the order they occur in the input stream.

This:
  • rq.Context
Name Type Description
values Array optional

The values to inspect.

Example
2 1 → intersection [2, 3] → 2

staticmodule:prelude.intersectionBy(values, iteratee)

This method is like intersection except that it accepts iteratee which is invoked for each element in values to generate the criterion by which they're compared. Result values are chosen from the input stream. The iteratee is invoked with one argument: (value).

This:
  • rq.Context
Name Type Default Description
values Array optional

The values to inspect.

iteratee function _.identity optional

The iteratee invoked per element.

Example
2.1 1.2 → intersectionBy [2.3, 3.4] (Math.floor) → 2.1
// The `property` iteratee shorthand.
{"x": 1} → intersectionBy [{"x": 2}, {"x": 1}] "x" → {"x": 1}

staticmodule:prelude.intersectionWith(values, comparator)

This method is like intersection except that it accepts comparator which is invoked to compare elements of values. Result values are chosen from the input stream. The comparator is invoked with two arguments: (arrVal, othVal).

This:
  • rq.Context
Name Type Description
values Array optional

The values to inspect.

comparator function optional

The comparator invoked per element.

Example
{"x": 1, "y": 2} {"x": 2, "y": 1} → intersectionWith [{"x": 1, "y": 1}, {"x": 1, "y": 2}] (_.isEqual) → {"x": 1, "y": 2}

staticmodule:prelude.invert()

Creates an object composed of the inverted keys and values of object. If object contains duplicate values, subsequent values overwrite property assignments of previous values.

This:
  • rq.Context
Example
{ "a": 1, "b": 2, "c": 1 } → invert → { "1": "c", "2": "b" }

staticmodule:prelude.invertBy(iteratee)

This method is like invert except that the inverted object is generated from the results of running each element of object thru iteratee. The corresponding inverted value of each inverted key is an array of keys responsible for generating the inverted value. The iteratee is invoked with one argument: (value).

This:
  • rq.Context
Name Type Default Description
iteratee function _.identity optional

The iteratee invoked per element.

Example
{ "a": 1, "b": 2, "c": 1 } → invertBy (v => "group" + v) → { "group1": ["a", "c"], "group2": ["b"] }

staticmodule:prelude.invoke(path, args)

Invokes the method at path of object.

This:
  • rq.Context
Name Type Description
path Array | string

The path of the method to invoke.

args * optional repeatable

The arguments to invoke the method with.

Example
{ "a": [{ "b": { "c": [1, 2, 3, 4] } }] } → invoke "a[0].b.c.slice" 1 3 → [2, 3]

staticmodule:prelude.invokeMap(path, args)

Invokes the method at path of each element in the input stream, returning an array of the results of each invoked method. Any additional arguments are provided to each invoked method. If path is a function, it's invoked for, and this bound to, each element in the input stream.

This:
  • rq.Context
Name Type Description
path Array | function | string

The path of the method to invoke or the function invoked per iteration.

args * optional repeatable

The arguments to invoke each method with.

Example
[5, 1, 7] [3, 2, 1] → invokeMap "sort" → [1, 5, 7] [1, 2, 3]
"123" "456" → invokeMap "split" "" → ["1", "2", "3"] ["4", "5", "6"]

staticmodule:prelude.isArray()

Checks if each input value is classified as an Array object.

This:
  • rq.Context
Example
[1, 2, 3] "abc" true {"length": 2} → isArray → true false false false

staticmodule:prelude.isArrayBuffer()

Checks if each input value is classified as an ArrayBuffer object.

This:
  • rq.Context

staticmodule:prelude.isArrayLike()

Checks if each input value is array-like. A value is considered array-like if it's not a function and has a value.length that's an integer greater than or equal to 0 and less than or equal to Number.MAX_SAFE_INTEGER.

This:
  • rq.Context
Example
[1, 2, 3] "abc" true {"length": 2} → isArrayLike → true true false true

staticmodule:prelude.isArrayLikeObject()

This method is like isArrayLike except that it also checks if value is an object.

This:
  • rq.Context
Example
[1, 2, 3] "abc" true {"length": 2} → isArrayLikeObject → true false false true

staticmodule:prelude.isBoolean()

Checks if each input value is classified as a boolean primitive or object.

This:
  • rq.Context
Example
false null → isBoolean → true false

staticmodule:prelude.isBuffer()

Checks if each input value is a buffer.

This:
  • rq.Context

staticmodule:prelude.isDate()

Checks if each input value is classified as a Date object.

This:
  • rq.Context

staticmodule:prelude.isEmpty()

Checks if value is an empty object, collection, map, or set.

Objects are considered empty if they have no own enumerable string keyed properties.

Array-like values such as arguments objects, arrays, buffers, strings, or jQuery-like collections are considered empty if they have a length of 0. Similarly, maps and sets are considered empty if they have a size of 0.

This:
  • rq.Context
Example
null true 1 [1, 2, 3] {"a": 1} → isEmpty → true true true false false

staticmodule:prelude.isEqual(other)

Performs a deep comparison between two values to determine if they are equivalent.

Note: This method supports comparing arrays, array buffers, booleans, date objects, error objects, maps, numbers, Object objects, regexes, sets, strings, symbols, and typed arrays. Object objects are compared by their own, not inherited, enumerable properties. Functions and DOM nodes are not supported.

This:
  • rq.Context
Name Type Description
other *

The other value to compare.

Example
{"a": 1} 2 {"a": 2} → isEqual {"a": 1} → true false false

staticmodule:prelude.isEqualWith(other, customizer)

This method is like isEqual except that it accepts customizer which is invoked to compare values. If customizer returns undefined, comparisons are handled by the method instead. The customizer is invoked with up to six arguments: (objValue, othValue [, index|key, object, other, stack]).

This:
  • rq.Context
Name Type Description
other *

The other value to compare.

customizer function optional

The function to customize comparisons.

Example
1.2 2.1 3.2 → isEqualWith 1.2 (x, y)=>{Math.floor(x) == Math.ceil(y)} → true false false

staticmodule:prelude.join(separator)

Converts all elements in the input stream into a string separated by separator.

This:
  • rq.Context
Name Type Default Description
separator string ',' optional

The element separator.

Example
"a" "b" "c" → join     → "a,b,c"
"a" "b" "c" → join "~" → "a~b~c"

staticmodule:prelude.kebabCase()

Converts each input string to kebab case.

This:
  • rq.Context
Example
"Foo Bar"     → kebabCase → "foo-bar"
"fooBar"      → kebabCase → "foo-bar"
"__FOO_BAR__" → kebabCase → "foo-bar"

staticmodule:prelude.keyBy(iteratee)

Creates an object composed of keys generated from the results of running each element of the input stream thru iteratee. The corresponding value of each key is the last element responsible for generating the key. The iteratee is invoked with one argument: (value).

This:
  • rq.Context
Name Type Default Description
iteratee function _.identity optional

The iteratee to transform keys.

Example
{"dir": "left", "code": 97} {"dir": "right", "code": 100} → keyBy (o)=>{String.fromCharCode(o.code)} → {"a": {"dir": "left", "code": 97}, "d": {"dir": "right", "code": 100}}
{"dir": "left", "code": 97} {"dir": "right", "code": 100} → keyBy "dir" → {"left": {"dir": "left", "code": 97}, "right": {"dir": "right", "code": 100}}

staticmodule:prelude.keys()

Creates an array of the own enumerable property names of object.

Note: Non-object values are coerced to objects. See the ES spec for more details.

This:
  • rq.Context
Example
{"a": 2, "b": 3} → keys → ["a", "b"]

staticmodule:prelude.last()

Gets the last element of the input stream.

This:
  • rq.Context
Example
1 2 3 → last → 3

staticmodule:prelude.lastIndexOf(value, fromIndex)

This method is like indexOf except that it iterates over elements of the input stream from right to left.

This:
  • rq.Context
Name Type Default Description
value *

The value to search for.

fromIndex number array.length-1 optional

The index to search from.

Example
1 2 1 2 → lastIndexOf 2   → 3
1 2 1 2 → lastIndexOf 2 2 → 1

staticmodule:prelude.lowerCase()

Converts each input string, as space separated words, to lower case.

This:
  • rq.Context
Example
"--Foo-Bar--" → lowerCase → "foo bar"
"fooBar"      → lowerCase → "foo bar"
"__FOO_BAR__" → lowerCase → "foo bar"

staticmodule:prelude.lowerFirst()

Converts each input string's first character to lower case.

This:
  • rq.Context
Example
"Fred" → lowerFirst → "fred"
"FRED" → lowerFirst → "fRED"

staticmodule:prelude.map(iteratee)

Creates a stream of values by running each element in the input stream thru iteratee. The iteratee is invoked with two arguments: (value, index).

Many lodash methods are guarded to work as iteratees for methods like every, filter, map, mapValues, reject, and some.

The guarded methods are: ary, chunk, curry, curryRight, drop, dropRight, every, fill, invert, parseInt, random, range, rangeRight, repeat, sampleSize, slice, some, sortBy, split, take, takeRight, template, trim, trimEnd, trimStart, and words

This:
  • rq.Context
Name Type Default Description
iteratee function _.identity optional

The function invoked per iteration.

Example
4 8 → map (x)=>{x*x} → 16 64
// With index
4 8 → map (x, i)=>{x + i} → 4 9
// The `property` iteratee shorthand.
{"u": "b"} {"u": "f"} → map "u" → "b" "f"

staticmodule:prelude.mapKeys(iteratee)

The opposite of mapValues; this method creates an object with the same values as object and keys generated by running each own enumerable string keyed property of object thru iteratee. The iteratee is invoked with three arguments: (value, key, object).

This:
  • rq.Context
Name Type Default Description
iteratee function _.identity optional

The function invoked per iteration.

Example
{"a": 1, "b": 2} → mapKeys (v, k) => {k + v} → {"a1": 1, "b2": 2}

staticmodule:prelude.mapValues(iteratee)

Creates an object with the same keys as object and values generated by running each own enumerable string keyed property of object thru iteratee. The iteratee is invoked with three arguments: (value, key, object).

This:
  • rq.Context
Name Type Default Description
iteratee function _.identity optional

The function invoked per iteration.

Example
{"a": 1, "b": 2} → mapValues (v, k) => {k + v} → {"a": "a1", "b": "b2"}

staticmodule:prelude.max()

Computes the maximum value of the input stream. If the input stream is empty or falsey, undefined is returned.

This:
  • rq.Context
Example
4 2 8 6 → max → 8
(empty) → max → null

staticmodule:prelude.maxBy(iteratee)

This method is like max except that it accepts iteratee which is invoked for each element in the input stream to generate the criterion by which the value is ranked. The iteratee is invoked with one argument: (value).

This:
  • rq.Context
Name Type Default Description
iteratee function _.identity optional

The iteratee invoked per element.

Example
{"n": 1} {"n": 2} → maxBy (o)=>{o.n} → {"n": 2}
// The `property` iteratee shorthand.
{"n": 1} {"n": 2} → maxBy "n" → {"n": 2}

staticmodule:prelude.mean()

Computes the mean of the values in the input stream.

This:
  • rq.Context
Example
4 2 8 6 → mean → 5
(empty) → mean → null

staticmodule:prelude.meanBy(iteratee)

This method is like mean except that it accepts iteratee which is invoked for each element in the input stream to generate the value to be averaged. The iteratee is invoked with one argument: (value).

This:
  • rq.Context
Name Type Default Description
iteratee function _.identity optional

The iteratee invoked per element.

Example
{"n": 4} {"n": 2} {"n": 8} {"n": 6} → meanBy (o)=>{o.n} → 5
// The `property` iteratee shorthand.
{"n": 4} {"n": 2} {"n": 8} {"n": 6} → meanBy "n" → 5

staticmodule:prelude.min()

Computes the minimum value of the input stream. If the input stream is empty or falsey, undefined is returned.

This:
  • rq.Context
Example
4 2 8 6 → min → 2
(empty) → min → null

staticmodule:prelude.minBy(iteratee)

This method is like min except that it accepts iteratee which is invoked for each element in the input stream to generate the criterion by which the value is ranked. The iteratee is invoked with one argument: (value).

This:
  • rq.Context
Name Type Default Description
iteratee function _.identity optional

The iteratee invoked per element.

Example
{"n": 1} {"n": 2} → minBy (o)=>{o.n} → {"n": 1}
// The `property` iteratee shorthand.
{"n": 1} {"n": 2} → minBy "n" → {"n": 1}

staticmodule:prelude.modify(path, f)

Modifies the field at the specified path for each value in the stream, using the specified function.

This:
  • rq.Context
Name Type Description
path string

the field path to follow

f function

the function to apply

Example
{"a": {"b": 2, "c": true}} → modify "/a/b" (n => n + 2) → {"a": {"b": 4, "c": true}}
{"a": {"b": 2, "c": true}} → modify "/a/x" (n => n + 2) → {"a": {"b": 2, "c": true}}

staticmodule:prelude.multiply(other)

Multiplies each element of the input stream by something.

This:
  • rq.Context
Name Type Description
other *

The factor.

Example
1 2 3 → multiply 2 → 2 4 6

staticmodule:prelude.now()

Gets the timestamp of the number of milliseconds that have elapsed since the Unix epoch (1 January 1970 00:00:00 UTC).

This:
  • rq.Context
Example
(empty) → now → 1470104632000 (not tested)

staticmodule:prelude.nth(n)

Gets the element at index n of the input stream. If n is negative, the nth element from the end is returned.

This:
  • rq.Context
Name Type Default Description
n number 0 optional

The index of the element to return.

Example
"a" "b" "c" "d" → nth  1 → "b"
"a" "b" "c" "d" → nth -2 → "c"

staticmodule:prelude.orderBy(iteratees, orders)

This method is like sortBy except that it allows specifying the sort orders of the iteratees to sort by. If orders is unspecified, all values are sorted in ascending order. Otherwise, specify an order of "desc" for descending or "asc" for ascending sort order of corresponding values.

This:
  • rq.Context
Name Type Default Description
iteratees Array.<Array> | Array.<function()> | Array.<Object> | Array.<string> [_.identity] optional

The iteratees to sort by.

orders Array.<string> optional

The sort orders of iteratees.

Example
{"u": "f", "g": 48} {"u": "b", "g": 34} {"u": "f", "g": 40} {"u": "b", "g": 36} → orderBy ["u", "g"] ["asc", "desc"] → {"u": "b", "g": 36} {"u": "b", "g": 34} {"u": "f", "g": 48} {"u": "f", "g": 40}

staticmodule:prelude.pad(length, chars)

Pads each input string on the left and right sides if it's shorter than length. Padding characters are truncated if they can't be evenly divided by length.

This:
  • rq.Context
Name Type Default Description
length number 0 optional

The padding length.

chars string ' ' optional

The string used as padding.

Example
"abc" → pad 8      → "  abc   "
"abc" → pad 8 "_-" → "_-abc_-_"
"abc" → pad 3      → "abc"

staticmodule:prelude.padEnd(length, chars)

Pads each input string on the right side if it's shorter than length. Padding characters are truncated if they can't be evenly divided by length.

This:
  • rq.Context
Name Type Default Description
length number 0 optional

The padding length.

chars string ' ' optional

The string used as padding.

Example
"abc" → padEnd 6      → "abc   "
"abc" → padEnd 6 "_-" → "abc_-_"
"abc" → padEnd 3      → "abc"

staticmodule:prelude.padStart(length, chars)

Pads each input string on the left side if it's shorter than length. Padding characters are truncated if they can't be evenly divided by length.

This:
  • rq.Context
Name Type Default Description
length number 0 optional

The padding length.

chars string ' ' optional

The string used as padding.

Example
"abc" → padStart 6      → "   abc"
"abc" → padStart 6 "_-" → "_-_abc"
"abc" → padStart 3      → "abc"

staticmodule:prelude.parseInt(radix)

Converts each input string to an integer of the specified radix. If radix is undefined or 0, a radix of 10 is used unless value is a hexadecimal, in which case a radix of 16 is used.

Note: This method aligns with the ES5 implementation of parseInt.

This:
  • rq.Context
Name Type Default Description
radix number 10 optional

The radix to interpret value by.

Example
"08"          → parseInt    → 8 (not tested)
"6" "08" "10" → parseInt    → 6 8 10 (not tested)
"a" "b" "c"   → parseInt 16 → 10 11 12 (not tested)

staticmodule:prelude.partition(predicate)

Creates a stream of elements split into two groups, the first of which contains elements predicate returns truthy for, the second of which contains elements predicate returns falsey for. The predicate is invoked with one argument: (value).

This:
  • rq.Context
Name Type Default Description
predicate function _.identity optional

The function invoked per iteration.

Example
{"u": "b", "g": 36, "a": false} {"u": "f", "g": 40, "a": true} {"u": "p", "g": 1, "a": false} → partition (o)=>{o.a} → [{"u": "f", "g": 40, "a": true}] [{"u": "b", "g": 36, "a": false}, {"u": "p", "g": 1, "a": false}]
// The `matches` iteratee shorthand.
{"u": "b", "g": 36, "a": false} {"u": "f", "g": 40, "a": true} {"u": "p", "g": 1, "a": false} → partition {"g": 1, "a": false} → [{"u": "p", "g": 1, "a": false}] [{"u": "b", "g": 36, "a": false}, {"u": "f", "g": 40, "a": true}]
// The `matchesProperty` iteratee shorthand.
{"u": "b", "g": 36, "a": false} {"u": "f", "g": 40, "a": true} {"u": "p", "g": 1, "a": false} → partition ["a", false] → [{"u": "b", "g": 36, "a": false}, {"u": "p", "g": 1, "a": false}] [{"u": "f", "g": 40, "a": true}]
// The `property` iteratee shorthand.
{"u": "b", "g": 36, "a": false} {"u": "f", "g": 40, "a": true} {"u": "p", "g": 1, "a": false} → partition "a" → [{"u": "f", "g": 40, "a": true}] [{"u": "b", "g": 36, "a": false}, {"u": "p", "g": 1, "a": false}]

staticmodule:prelude.random(lower, upper, floating)

Produces a random number between the inclusive lower and upper bounds. If only one argument is provided a number between 0 and the given number is returned. If floating is true, or either lower or upper are floats, a floating-point number is returned instead of an integer.

Note: JavaScript follows the IEEE-754 standard for resolving floating-point values which can produce unexpected results.

This:
  • rq.Context
Name Type Default Description
lower number 0 optional

The lower bound.

upper number 1 optional

The upper bound.

floating boolean optional

Specify returning a floating-point number.

Example
(empty) → random 0 5 → 2 (not tested)
(empty) → random 5 → 3 (not tested)
(empty) → random 5 true → 3.2 (not tested)
(empty) → random 1.2 1.5 → 1.3 (not tested)

staticmodule:prelude.reduce(iteratee, accumulator)

Reduces the input stream to a value which is the accumulated result of running each element in the input stream thru iteratee, where each successive invocation is supplied the return value of the previous. If accumulator is not given, the first element of the input stream is used as the initial value. The iteratee is invoked with four arguments: (accumulator, value, index|key, collection).

Many lodash methods are guarded to work as iteratees for methods like reduce, reduceRight, and transform.

The guarded methods are: assign, defaults, defaultsDeep, includes, merge, orderBy, and sortBy

This:
  • rq.Context
Name Type Default Description
iteratee function _.identity optional

The function invoked per iteration.

accumulator * optional

The initial value.

See:
  • _.reduceRight
Example
1 2 → reduce (sum, n)=>{sum + n} 0 → 3

staticmodule:prelude.reduceRight(iteratee, accumulator)

This method is like reduce except that it iterates over elements of the input stream from right to left.

This:
  • rq.Context
Name Type Default Description
iteratee function _.identity optional

The function invoked per iteration.

accumulator * optional

The initial value.

See:
  • _.reduce
Example
[0, 1] [2, 3] [4, 5] → reduceRight (flattened, other)=>{flattened.concat(other)} [] → [4, 5, 2, 3, 0, 1]

staticmodule:prelude.reject(predicate)

The opposite of filter; this method returns the elements of the input stream that predicate does not return truthy for.

This:
  • rq.Context
Name Type Default Description
predicate function _.identity optional

The function invoked per iteration.

See:
  • _.filter
Example
{"u": "b", "g": 36, "a": false} {"u": "f", "g": 40, "a": true} → reject (o)=>{!o.a} → {"u": "f", "g": 40, "a": true}
// The `matches` iteratee shorthand.
{"u": "b", "g": 36, "a": false} {"u": "f", "g": 40, "a": true} → reject {"g": 40, "a": true} → {"u": "b", "g": 36, "a": false}
// The `matchesProperty` iteratee shorthand.
{"u": "b", "g": 36, "a": false} {"u": "f", "g": 40, "a": true} → reject ["a", false] → {"u": "f", "g": 40, "a": true}
// The `property` iteratee shorthand.
{"u": "b", "g": 36, "a": false} {"u": "f", "g": 40, "a": true} → reject "a" → {"u": "b", "g": 36, "a": false}

staticmodule:prelude.repeat(n)

Repeats each input string n times.

This:
  • rq.Context
Name Type Default Description
n number 1 optional

The number of times to repeat the string.

Example
"*"   → repeat 3 → "***"
"abc" → repeat 2 → "abcabc"
"abc" → repeat 0 → ""

staticmodule:prelude.replace(pattern, replacement)

Replaces matches for pattern in each input string with replacement.

Note: This method is based on String#replace. Repeats each input string n times.

This:
  • rq.Context
Name Type Description
pattern RegExp | string

The pattern to replace.

replacement function | string

The match replacement.

Example
"Hi Fred" → replace "Fred" "Barney" → "Hi Barney"

staticmodule:prelude.reverse()

Reverses the input stream so that the first element becomes the last, the second element becomes the second to last, and so on.

This:
  • rq.Context
Example
1 2 3 → reverse → 3 2 1

staticmodule:prelude.round(precision)

Rounds each element of the input stream to precision.

This:
  • rq.Context
Name Type Default Description
precision number 0 optional

The precision to round to.

Example
4.006 → round    → 4
4.006 → round  2 → 4.01
4060  → round -2 → 4100

staticmodule:prelude.sample()

Gets a random element from the input stream.

This:
  • rq.Context
Example
1 2 3 4 → sample → 2 (not tested)

staticmodule:prelude.sampleSize(n)

Gets n random elements at unique keys from the input stream up to the size of the input stream.

This:
  • rq.Context
Name Type Default Description
n number 1 optional

The number of elements to sample.

Example
1 2 3 → sampleSize 2 → 3 1 (not tested)
1 2 3 → sampleSize 4 → 2 3 1 (not tested)

staticmodule:prelude.select(path)

Selects the field(s) at the specified path for each value in the stream.

This:
  • rq.Context
Name Type Description
path string

the field path to follow

Example
{"a": {"b": {"c": 3}}} → select "/a/b" → {"c": 3}
{"a": {"b": {"c": 3}}} → select "/a/x" → (empty)

staticmodule:prelude.shuffle()

Creates a stream of shuffled values, using a version of the Fisher-Yates shuffle.

This:
  • rq.Context
Example
1 2 3 4 → shuffle → 4 1 3 2 (not tested)

staticmodule:prelude.size()

Gets the size of the input stream by returning its length.

This:
  • rq.Context
Example
1 2 3 → size → 3

staticmodule:prelude.slice(start, end)

Creates a slice of the input stream from start up to, but not including, end.

This:
  • rq.Context
Name Type Default Description
start number 0 optional

The start position.

end number array.length optional

The end position.

Example
1 2 3 4 → slice 1 3 → 2 3

staticmodule:prelude.snakeCase()

Converts each input string to snake case.

This:
  • rq.Context
Example
"Foo Bar"     → snakeCase → "foo_bar"
"fooBar"      → snakeCase → "foo_bar"
"--FOO-BAR--" → snakeCase → "foo_bar"

staticmodule:prelude.some(predicate)

Checks if predicate returns truthy for any element of the input stream. Iteration is stopped once predicate returns truthy. The predicate is invoked with two arguments: (value, index).

This:
  • rq.Context
Name Type Default Description
predicate function _.identity optional

The function invoked per iteration.

Example
null 0 "yes" false → some (x)=>{Boolean(x)} → true
// With index
5 1 8 → some (x, i) => { i == x } → true
// The `matches` iteratee shorthand.
{"u": "b", "a": true} {"u": "f", "a": false} → some {"u": "b", "a": false} → false
// The `matchesProperty` iteratee shorthand.
{"u": "b", "a": true} {"u": "f", "a": false} → some ["a", false] → true
// The `property` iteratee shorthand.
{"u": "b", "a": true} {"u": "f", "a": false} → some "a" → true

staticmodule:prelude.sort()

Creates a stream of elements, with the input sorted in ascending order. This method performs a stable sort, that is, it preserves the original sort order of equal elements.

This:
  • rq.Context
Example
3 1 2 → sort → 1 2 3

staticmodule:prelude.sortBy(iteratees)

Creates a stream of elements, sorted in ascending order by the results of running each element in a collection thru each iteratee. This method performs a stable sort, that is, it preserves the original sort order of equal elements. The iteratees are invoked with one argument: (value).

This:
  • rq.Context
Name Type Default Description
iteratees function | Array.<function()> [_.identity] optional repeatable

The iteratees to sort by.

Example
{"u": "f", "g": 48} {"u": "b", "g": 36} {"u": "f", "g": 40} {"u": "b", "g": 34} → sortBy (o)=>{o.u} → {"u": "b", "g": 36} {"u": "b", "g": 34} {"u": "f", "g": 48} {"u": "f", "g": 40}
{"u": "f", "g": 48} {"u": "b", "g": 36} {"u": "f", "g": 40} {"u": "b", "g": 34} → sortBy ["u", "g"] → {"u": "b", "g": 34} {"u": "b", "g": 36} {"u": "f", "g": 40} {"u": "f", "g": 48}
{"u": "f", "g": 48} {"u": "b", "g": 36} {"u": "f", "g": 40} {"u": "b", "g": 34} → sortBy "u" (o)=>{o.a/10} → {"u": "b", "g": 36} {"u": "b", "g": 34} {"u": "f", "g": 48} {"u": "f", "g": 40}

staticmodule:prelude.sortedIndex(value)

Uses a binary search to determine the lowest index at which value should be inserted into the input stream in order to maintain its sort order.

This:
  • rq.Context
Name Type Description
value *

The value to evaluate. into the input stream.

Example
30 50 → sortedIndex 40 → 1

staticmodule:prelude.sortedIndexBy(value, iteratee)

This method is like sortedIndex except that it accepts iteratee which is invoked for value and each element of the input stream to compute their sort ranking. The iteratee is invoked with one argument: (value).

This:
  • rq.Context
Name Type Default Description
value *

The value to evaluate.

iteratee function _.identity optional

The iteratee invoked per element. into the input stream.

Example
{"x": 4} {"x": 5} → sortedIndexBy {"x": 4} (o => o.x) → 0
// The `property` iteratee shorthand.
{"x": 4} {"x": 5} → sortedIndexBy {"x": 4} "x" → 0

staticmodule:prelude.sortedIndexOf(value)

This method is like indexOf except that it performs a binary search on a sorted the input stream.

This:
  • rq.Context
Name Type Description
value *

The value to search for.

Example
4 5 5 5 6 → sortedIndexOf 5 → 1

staticmodule:prelude.sortedLastIndex(value)

This method is like sortedIndex except that it returns the highest index at which value should be inserted into the input stream in order to maintain its sort order.

This:
  • rq.Context
Name Type Description
value *

The value to evaluate. into the input stream.

Example
4 5 5 5 6 → sortedLastIndex 5 → 4

staticmodule:prelude.sortedLastIndexBy(value, iteratee)

This method is like sortedLastIndex except that it accepts iteratee which is invoked for value and each element of the input stream to compute their sort ranking. The iteratee is invoked with one argument: (value).

This:
  • rq.Context
Name Type Default Description
value *

The value to evaluate.

iteratee function _.identity optional

The iteratee invoked per element. into the input stream.

Example
{"x": 4} {"x": 5} → sortedLastIndexBy {"x": 4} (o => o.x) → 1
// The `property` iteratee shorthand.
{"x": 4} {"x": 5} → sortedLastIndexBy {"x": 4} "x" → 1

staticmodule:prelude.sortedLastIndexOf(value)

This method is like lastIndexOf except that it performs a binary search on a sorted the input stream.

This:
  • rq.Context
Name Type Description
value *

The value to search for.

Example
4 5 5 5 6 → sortedLastIndexOf 5 → 3

staticmodule:prelude.sortedUniq()

This method is like uniq except that it's designed and optimized for sorted arrays.

This:
  • rq.Context
Example
1 1 2 → sortedUniq → 1 2

staticmodule:prelude.sortedUniqBy(iteratee)

This method is like uniqBy except that it's designed and optimized for sorted arrays.

This:
  • rq.Context
Name Type Description
iteratee function optional

The iteratee invoked per element.

Example
1.1 1.2 2.3 2.4 → sortedUniqBy (Math.floor) → 1.1 2.3

staticmodule:prelude.split(separator, limit)

Splits each input string by separator.

This:
  • rq.Context
Name Type Description
separator RegExp | string

The separator pattern to split by.

limit number optional

The length to truncate results to.

Example
"a-b-c" → split "-"   → ["a", "b", "c"]
"a-b-c" → split "-" 2 → ["a", "b"]

staticmodule:prelude.spread()

Spreads each array in the input stream into separate output values.

This:
  • rq.Context
Example
[1, 2] [3, 4] 5 → spread → 1 2 3 4 5

staticmodule:prelude.startCase()

Converts each input string to start case.

This:
  • rq.Context
Example
"--foo-bar--" → startCase → "Foo Bar"
"fooBar"      → startCase → "Foo Bar"
"__FOO_BAR__" → startCase → "FOO BAR"

staticmodule:prelude.startsWith(target, position)

Checks if each input string starts with the given target string.

This:
  • rq.Context
Name Type Default Description
target string optional

The string to search for.

position number 0 optional

The position to search from.

Example
"abc" → startsWith "a"   → true
"abc" → startsWith "b"   → false
"abc" → startsWith "b" 1 → true

staticmodule:prelude.subtract(other)

Subtracts something from each element of the input stream.

This:
  • rq.Context
Name Type Description
other *

The subtrahend.

Example
1 2 3 → subtract 1 → 0 1 2

staticmodule:prelude.sum()

Computes the sum of the values in the input stream.

This:
  • rq.Context
Example
4 2 8 6 → sum → 20
(empty) → sum → 0

staticmodule:prelude.sumBy(iteratee)

This method is like sum except that it accepts iteratee which is invoked for each element in the input stream to generate the value to be summed. The iteratee is invoked with one argument: (value).

This:
  • rq.Context
Name Type Default Description
iteratee function _.identity optional

The iteratee invoked per element.

Example
{"n": 4} {"n": 2} {"n": 8} {"n": 6} → sumBy (o)=>{o.n} → 20
// The `property` iteratee shorthand.
{"n": 4} {"n": 2} {"n": 8} {"n": 6} → sumBy "n" → 20

staticmodule:prelude.tail()

Gets all but the first element of the input stream.

This:
  • rq.Context
Example
1 2 3 → tail → 2 3

staticmodule:prelude.take(n)

Creates a slice of the input stream with n elements taken from the beginning.

This:
  • rq.Context
Name Type Default Description
n number 1 optional

The number of elements to take.

Example
1 2 3 → take   → 1
1 2 3 → take 2 → 1 2
1 2 3 → take 5 → 1 2 3
1 2 3 → take 0 → (empty)

staticmodule:prelude.takeRight(n)

Creates a slice of the input stream with n elements taken from the end.

This:
  • rq.Context
Name Type Default Description
n number 1 optional

The number of elements to take.

Example
1 2 3 → takeRight   → 3
1 2 3 → takeRight 2 → 2 3
1 2 3 → takeRight 5 → 1 2 3
1 2 3 → takeRight 0 → (empty)

staticmodule:prelude.takeRightWhile(predicate)

Creates a slice of the input stream with elements taken from the end. Elements are taken until predicate returns falsey. The predicate is invoked with three arguments: (value, index, array).

This:
  • rq.Context
Name Type Default Description
predicate function _.identity optional

The function invoked per iteration.

Example
{"u": "b", "a": true} {"u": "f", "a": false} {"u": "p", "a": false} → takeRightWhile (o => !o.a) → {"u": "f", "a": false} {"u": "p", "a": false}
// The `matches` iteratee shorthand.
{"u": "b", "a": true} {"u": "f", "a": false} {"u": "p", "a": false} → takeRightWhile {"u": "p", "a": false} → {"u": "p", "a": false}
// The `matchesProperty` iteratee shorthand.
{"u": "b", "a": true} {"u": "f", "a": false} {"u": "p", "a": false} → takeRightWhile ["a", false] → {"u": "f", "a": false} {"u": "p", "a": false}
// The `property` iteratee shorthand.
{"u": "b", "a": true} {"u": "f", "a": false} {"u": "p", "a": false} → takeRightWhile "a" → (empty)

staticmodule:prelude.takeWhile(predicate)

Creates a slice of the input stream with elements taken from the beginning. Elements are taken until predicate returns falsey. The predicate is invoked with three arguments: (value, index, array).

This:
  • rq.Context
Name Type Default Description
predicate function _.identity optional

The function invoked per iteration.

Example
{"u": "b", "a": false} {"u": "f", "a": false} {"u": "p", "a": true} → takeWhile (o => !o.a) → {"u": "b", "a": false} {"u": "f", "a": false}
// The `matches` iteratee shorthand.
{"u": "b", "a": false} {"u": "f", "a": false} {"u": "p", "a": true} → takeWhile {"u": "b", "a": false} → {"u": "b", "a": false}
// The `matchesProperty` iteratee shorthand.
{"u": "b", "a": false} {"u": "f", "a": false} {"u": "p", "a": true} → takeWhile ["a", false] → {"u": "b", "a": false} {"u": "f", "a": false}
// The `property` iteratee shorthand.
{"u": "b", "a": false} {"u": "f", "a": false} {"u": "p", "a": true} → takeWhile "a" → (empty)

staticmodule:prelude.tee()

Logs each value that passes through to the info log.

This:
  • rq.Context

staticmodule:prelude.template(string, options)

Creates a compiled template function that can interpolate data properties in "interpolate" delimiters, HTML-escape interpolated data properties in "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data properties may be accessed as free variables in the template. If a setting object is given, it takes precedence over _.templateSettings values.

Note: In the development build _.template utilizes sourceURLs for easier debugging.

For more information on precompiling templates see lodash's custom builds documentation.

For more information on Chrome extension sandboxes see Chrome's extensions documentation.

This:
  • rq.Context
Name Type Default Description
string string '' optional

The template string.

options Object {} optional

The options object.

Name Type Default Description
escape RegExp _.templateSettings.escape optional

The HTML "escape" delimiter.

evaluate RegExp _.templateSettings.evaluate optional

The "evaluate" delimiter.

imports Object _.templateSettings.imports optional

An object to import into the template as free variables.

interpolate RegExp _.templateSettings.interpolate optional

The "interpolate" delimiter.

sourceURL string 'lodash.templateSources[n]' optional

The sourceURL of the compiled template.

variable string 'obj' optional

The data object variable name.

Example
// Use the "interpolate" delimiter to create a compiled template.
{"user": "fred"} → template "hello <%= user %>!" → "hello fred!"

// Use the HTML "escape" delimiter to escape data property values.
{"value": "<script>"} → template "<b><%- value %></b>" → "<b>&lt;script&gt;</b>"

// Use the "evaluate" delimiter to execute JavaScript and generate HTML.
{"users": ["fred", "barney"]} → template "<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>" → "<li>fred</li><li>barney</li>"

// Use the internal `print` function in "evaluate" delimiters.
{"user": "barney"} → template "<% print('hello ' + user); %>!" → "hello barney!"

// Use backslashes to treat delimiters as plain text.
{"value": "ignored"} → template "<%= '\\<%- value %\\>' %>" → "<%- value %>"

// Use the `variable` option to ensure a with-statement isn't used
// in the compiled template.
{"user": "barney"} → template "hi <%= data.user %>!" {"variable": "data"} → "hi barney!"

staticmodule:prelude.toLower()

Converts each input string, as a whole, to lower case just like String#toLowerCase.

This:
  • rq.Context
Example
"--Foo-Bar--" → toLower → "--foo-bar--"
"fooBar"      → toLower → "foobar"
"__FOO_BAR__" → toLower → "__foo_bar__"

staticmodule:prelude.toUpper()

Converts each input string, as a whole, to upper case just like String#toUpperCase.

This:
  • rq.Context
Example
"--foo-bar--" → toUpper → "--FOO-BAR--"
"fooBar"      → toUpper → "FOOBAR"
"__foo_bar__" → toUpper → "__FOO_BAR__"

staticmodule:prelude.trim()

Removes leading and trailing whitespace or specified characters from each input string.

This:
  • rq.Context
Example
"  abc  "   → trim      → "abc"
"-_-abc-_-" → trim "_-" → "abc"

staticmodule:prelude.trimEnd(chars)

Removes trailing whitespace or specified characters from each input string.

This:
  • rq.Context
Name Type Default Description
chars string whitespace optional

The characters to trim.

Example
"  abc  "   → trimEnd      → "  abc"
"-_-abc-_-" → trimEnd "_-" → "-_-abc"

staticmodule:prelude.trimStart(chars)

Removes leading whitespace or specified characters from each input string.

This:
  • rq.Context
Name Type Default Description
chars string whitespace optional

The characters to trim.

Example
"  abc  "   → trimStart      → "abc  "
"-_-abc-_-" → trimStart "_-" → "abc-_-"

staticmodule:prelude.truncate(options)

Truncates each input string if it's longer than the given maximum string length. The last characters of the truncated string are replaced with the omission string which defaults to"...".

This:
  • rq.Context
Name Type Default Description
options Object {} optional

The options object.

Name Type Default Description
length number 30 optional

The maximum string length.

omission string '...' optional

The string to indicate text is omitted.

separator RegExp | string optional

The separator pattern to truncate to.

Example
"hi-diddly-ho there, neighborino" → truncate → "hi-diddly-ho there, neighbo..."
"hi-diddly-ho there, neighborino" → truncate {length: 24, separator: " "} → "hi-diddly-ho there,..."
"hi-diddly-ho there, neighborino" → truncate {omission: " [...]"} → "hi-diddly-ho there, neig [...]"

staticmodule:prelude.unescape()

The inverse of _.escape; this method converts the HTML entities &amp;, &lt;, &gt;, &quot;, and &#39; in string to their corresponding characters.

Note: No other HTML entities are unescaped. To unescape additional HTML entities use a third-party library like he.

This:
  • rq.Context
Example
"fred, barney, & pebbles" → unescape → "fred, barney, & pebbles"

staticmodule:prelude.union(values)

Creates a stream of unique values, in order, from all given values using SameValueZero for equality comparisons.

This:
  • rq.Context
Name Type Description
values Array optional

The values to inspect.

Example
2 → union [1, 2] → 2 1

staticmodule:prelude.unionBy(values, iteratee)

This method is like union except that it accepts iteratee which is invoked for each element of values to generate the criterion by which uniqueness is computed. Result values are chosen from the input stream. The iteratee is invoked with one argument: (value).

This:
  • rq.Context
Name Type Default Description
values Array optional

The values to inspect.

iteratee function _.identity optional

The iteratee invoked per element.

Example
2.1 → unionBy [1.2, 2.3] (Math.floor) → 2.1 1.2
// The `property` iteratee shorthand.
{"x": 1} → unionBy [{"x": 2}, {"x": 1}] "x" → {"x": 1} {"x": 2}

staticmodule:prelude.unionWith(values, comparator)

This method is like union except that it accepts comparator which is invoked to compare elements of values. Result values are chosen from the input stream. The comparator is invoked with two arguments: (arrVal, othVal).

This:
  • rq.Context
Name Type Description
values Array optional

The values to inspect.

comparator function optional

The comparator invoked per element.

Example
{"x": 1, "y": 2} {"x": 2, "y": 1} → unionWith [{"x": 1, "y": 1}, {"x": 1, "y": 2}] (_.isEqual) → {"x": 1, "y": 2} {"x": 2, "y": 1} {"x": 1, "y": 1}

staticmodule:prelude.uniq()

Creates a duplicate-free version of the input stream, using SameValueZero for equality comparisons, in which only the first occurrence of each element is kept.

This:
  • rq.Context
Example
2 1 2 → uniq → 2 1

staticmodule:prelude.uniqBy(iteratee)

This method is like uniq except that it accepts iteratee which is invoked for each element in the input stream to generate the criterion by which uniqueness is computed. The iteratee is invoked with one argument: (value).

This:
  • rq.Context
Name Type Default Description
iteratee function _.identity optional

The iteratee invoked per element.

Example
2.1 1.2 2.3 → uniqBy (Math.floor) → 2.1 1.2
// The `property` iteratee shorthand.
{"x": 1} {"x": 2} {"x": 1} → uniqBy "x" → {"x": 1} {"x": 2}

staticmodule:prelude.uniqWith(comparator)

This method is like uniq except that it accepts comparator which is invoked to compare elements of the input stream. The comparator is invoked with two arguments: (arrVal, othVal).

This:
  • rq.Context
Name Type Description
comparator function optional

The comparator invoked per element.

Example
{"x": 1, "y": 2} {"x": 2, "y": 1} {"x": 1, "y": 2} → uniqWith (_.isEqual) → {"x": 1, "y": 2} {"x": 2, "y": 1}

staticmodule:prelude.unzip()

This method is like zip except that it accepts a stream of grouped elements and creates an array regrouping the elements to their pre-zip configuration.

This:
  • rq.Context
Example
["a", 1, true] ["b", 2, false] → unzip → ["a", "b"] [1, 2] [true, false]

staticmodule:prelude.unzipWith(iteratee)

This method is like unzip except that it accepts iteratee to specify how regrouped values should be combined. The iteratee is invoked with the elements of each group: (...group).

This:
  • rq.Context
Name Type Default Description
iteratee function _.identity optional

The function to combine regrouped values.

Example
[1, 10, 100] [2, 20, 200] → unzipWith (_.add) → 3 30 300

staticmodule:prelude.upperCase()

Converts each input string, as space separated words, to upper case.

This:
  • rq.Context
Example
"--foo-bar"   → upperCase → "FOO BAR"
"fooBar"      → upperCase → "FOO BAR"
"__FOO_BAR__" → upperCase → "FOO BAR"

staticmodule:prelude.upperFirst()

Converts the first character of each input string to upper case.

This:
  • rq.Context
Example
"fred" → upperFirst → "Fred"
"FRED" → upperFirst → "FRED"

staticmodule:prelude.without(values)

Creates a stream excluding all given values using SameValueZero for equality comparisons.

This:
  • rq.Context
Name Type Description
values * optional repeatable

The values to exclude.

See:
  • _.difference, _.xor
Example
2 1 2 3 → without 1 2 → 3

staticmodule:prelude.words(pattern)

Splits each input string into an array of its words.

This:
  • rq.Context
Name Type Description
pattern RegExp | string optional

The pattern to match words.

Example
"fred, barney, & pebbles" → words          → ["fred", "barney", "pebbles"]

staticmodule:prelude.xor(values)

Creates a stream of unique values that is the symmetric difference of the given values. The order of result values is determined by the order they occur in the input stream.

This:
  • rq.Context
Name Type Description
values Array optional

The values to inspect.

See:
  • _.difference, _.without
Example
2 1 → xor [2, 3] → 1 3

staticmodule:prelude.xorBy(values, iteratee)

This method is like xor except that it accepts iteratee which is invoked for each element of each values to generate the criterion by which by which they're compared. The iteratee is invoked with one argument: (value).

This:
  • rq.Context
Name Type Default Description
values Array optional

The arrays to inspect.

iteratee function _.identity optional

The iteratee invoked per element.

Example
2.1 1.2 → xorBy [2.3, 3.4] (Math.floor) → 1.2 3.4
// The `property` iteratee shorthand.
{"x": 1} → xorBy [{"x": 2}, {"x": 1}] "x" → {"x": 2}

staticmodule:prelude.xorWith(values, comparator)

This method is like xor except that it accepts comparator which is invoked to compare elements of values. The comparator is invoked with two arguments: (arrVal, othVal).

This:
  • rq.Context
Name Type Description
values Array optional

The values to inspect.

comparator function optional

The comparator invoked per element.

Example
{"x": 1, "y": 2} {"x": 2, "y": 1} → xorWith [{"x": 1, "y": 1}, {"x": 1, "y": 2}] (_.isEqual) → {"x": 2, "y": 1} {"x": 1, "y": 1}

staticmodule:prelude.zip()

Creates a stream of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second elements of the given arrays, and so on.

This:
  • rq.Context
Example
["a", "b"] [1, 2] [true, false] → zip → ["a", 1, true] ["b", 2, false]

staticmodule:prelude.zipWith(iteratee)

This method is like zip except that it accepts iteratee to specify how grouped values should be combined. The iteratee is invoked with the elements of each group: (...group).

This:
  • rq.Context
Name Type Default Description
iteratee function _.identity optional

The function to combine grouped values.

Example
[1, 2] [10, 20] [100, 200] → zipWith (a, b, c)=>{a + b + c} → 111 222