all


(a → Boolean) → [a] → Boolean

Parameters

  • fnThe predicate function.
  • listThe array to consider.

Returns Boolean true if the predicate is satisfied by every element, false otherwise.

Added in v0.1.0

Returns true if all elements of the list match the predicate, false if there are any that don’t.

Dispatches to the all method of the second argument, if present.

Acts as a transducer if a transformer is given in list position.

See also any, none, transduce.

  1. const equals3 = R.equals(3);
  2. R.all(equals3)([3, 3, 3, 3]); //=> true
  3. R.all(equals3)([3, 3, 1, 3]); //=> false

any


(a → Boolean) → [a] → Boolean

Parameters

  • fnThe predicate function.
  • listThe array to consider.

Returns Boolean true if the predicate is satisfied by at least one element, false otherwise.

Added in v0.1.0

Returns true if at least one of the elements of the list match the predicate, false otherwise.

Dispatches to the any method of the second argument, if present.

Acts as a transducer if a transformer is given in list position.

See also all, none, transduce.

  1. const lessThan0 = R.flip(R.lt)(0);
  2. const lessThan2 = R.flip(R.lt)(2);
  3. R.any(lessThan0)([1, 2]); //=> false
  4. R.any(lessThan2)([1, 2]); //=> true

append


a → [a] → [a]

Parameters

  • elThe element to add to the end of the new list.
  • listThe list of elements to add a new item to. list.

Returns Array A new list containing the elements of the old list followed by el.

Added in v0.1.0

Returns a new list containing the contents of the given list, followed by the given element.

See also prepend.

  1. R.append('tests', ['write', 'more']); //=> ['write', 'more', 'tests']
  2. R.append('tests', []); //=> ['tests']
  3. R.append(['tests'], ['write', 'more']); //=> ['write', 'more', ['tests']]

concat


[a] → [a] → [a]

String → String → String

Parameters

  • firstListThe first list
  • secondListThe second list

Returns Array A list consisting of the elements of firstList followed by the elements of secondList.

Added in v0.1.0

Returns the result of concatenating the given lists or strings.

Note: R.concat expects both arguments to be of the same type, unlike the native Array.prototype.concat method. It will throw an error if you concat an Array with a non-Array value.

Dispatches to the concat method of the first argument, if present. Can also concatenate two members of a fantasy-land compatible semigroup.

  1. R.concat('ABC', 'DEF'); // 'ABCDEF'
  2. R.concat([4, 5, 6], [1, 2, 3]); //=> [4, 5, 6, 1, 2, 3]
  3. R.concat([], []); //=> []

drop


Number → [a] → [a]

Number → String → String

Parameters

  • n
  • list

Returns * A copy of list without the first n elements

Added in v0.1.0

Returns all but the first n elements of the given list, string, or transducer/transformer (or object with a drop method).

Dispatches to the drop method of the second argument, if present.

See also take, transduce, dropLast, dropWhile.

  1. R.drop(1, ['foo', 'bar', 'baz']); //=> ['bar', 'baz']
  2. R.drop(2, ['foo', 'bar', 'baz']); //=> ['baz']
  3. R.drop(3, ['foo', 'bar', 'baz']); //=> []
  4. R.drop(4, ['foo', 'bar', 'baz']); //=> []
  5. R.drop(3, 'ramda'); //=> 'da'

zipWith


((a, b) → c) → [a] → [b] → [c]

Parameters

  • fnThe function used to combine the two elements into one value.
  • list1The first array to consider.
  • list2The second array to consider.

Returns Array The list made by combining same-indexed elements of list1 and list2 using fn.

Added in v0.1.0

Creates a new list out of the two supplied by applying the function to each equally-positioned pair in the lists. The returned list is truncated to the length of the shorter of the two input lists.

  1. const f = (x, y) => {
  2. // ...
  3. };
  4. R.zipWith(f, [1, 2, 3], ['a', 'b', 'c']);
  5. //=> [f(1, 'a'), f(2, 'b'), f(3, 'c')]

zip


[a] → [b] → [[a,b]]

Parameters

  • list1The first array to consider.
  • list2The second array to consider.

Returns Array The list made by pairing up same-indexed elements of list1 and list2.

Added in v0.1.0

Creates a new list out of the two supplied by pairing up equally-positioned items from both lists. The returned list is truncated to the length of the shorter of the two input lists. Note: zip is equivalent to zipWith(function(a, b) { return [a, b] }).

  1. R.zip([1, 2, 3], ['a', 'b', 'c']); //=> [[1, 'a'], [2, 'b'], [3, 'c']]

xprod


[a] → [b] → [[a,b]]

Parameters

  • asThe first list.
  • bsThe second list.

Returns Array The list made by combining each possible pair from as and bs into pairs ([a, b]).

Added in v0.1.0

Creates a new list out of the two supplied by creating each possible pair from the lists.

  1. R.xprod([1, 2], ['a', 'b']); //=> [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]

uniq


[a] → [a]

Parameters

  • listThe array to consider.

Returns Array The list of unique items.

Added in v0.1.0

Returns a new list containing only one copy of each element in the original list. R.equals is used to determine equality.

  1. R.uniq([1, 1, 2, 1]); //=> [1, 2]
  2. R.uniq([1, '1']); //=> [1, '1']
  3. R.uniq([[42], [42]]); //=> [[42]]

filter


Filterable f => (a → Boolean) → f a → f a

Parameters

  • pred
  • filterable

Returns Array Filterable

Added in v0.1.0

Takes a predicate and a Filterable, and returns a new filterable of the same type containing the members of the given filterable which satisfy the given predicate. Filterable objects include plain objects or any object that has a filter method such as Array.

Dispatches to the filter method of the second argument, if present.

Acts as a transducer if a transformer is given in list position.

See also reject, transduce, addIndex.

  1. const isEven = n => n % 2 === 0;
  2. R.filter(isEven, [1, 2, 3, 4]); //=> [2, 4]
  3. R.filter(isEven, {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, d: 4}

find


(a → Boolean) → [a] → a | undefined

Parameters

  • fnThe predicate function used to determine if the element is the desired one.
  • listThe array to consider.

Returns Object The element found, or undefined.

Added in v0.1.0

Returns the first element of the list which matches the predicate, or undefined if no element matches.

Dispatches to the find method of the second argument, if present.

Acts as a transducer if a transformer is given in list position.

See also transduce.

  1. const xs = [{a: 1}, {a: 2}, {a: 3}];
  2. R.find(R.propEq(2, 'a'))(xs); //=> {a: 2}
  3. R.find(R.propEq(4, 'a'))(xs); //=> undefined

flatten


[a] → [b]

Parameters

  • listThe array to consider.

Returns Array The flattened list.

Added in v0.1.0

Returns a new list by pulling every item out of it (and all its sub-arrays) and putting them in a new array, depth-first.

See also unnest.

  1. R.flatten([1, 2, [3, 4], 5, [6, [7, 8, [9, [10, 11], 12]]]]);
  2. //=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

head


[a] → a | Undefined

String → String | Undefined

Added in v0.1.0

Returns the first element of the given list or string. In some libraries this function is named first.

See also tail, init, last.

  1. R.head(['fi', 'fo', 'fum']); //=> 'fi'
  2. R.head([]); //=> undefined
  3. R.head('abc'); //=> 'a'
  4. R.head(''); //=> undefined

indexOf


a → [a] → Number

Parameters

  • targetThe item to find.
  • xsThe array to search in.

Returns Number the index of the target, or -1 if the target is not found.

Added in v0.1.0

Returns the position of the first occurrence of an item in an array, or -1 if the item is not included in the array. R.equals is used to determine equality.

See also lastIndexOf, findIndex.

  1. R.indexOf(3, [1,2,3,4]); //=> 2
  2. R.indexOf(10, [1,2,3,4]); //=> -1

join


String → [a] → String

Parameters

  • separatorThe string used to separate the elements.
  • xsThe elements to join into a string.

Returns String str The string made by concatenating xs with separator.

Added in v0.1.0

Returns a string made by inserting the separator between each element and concatenating all the elements into a single string.

See also split.

  1. const spacer = R.join(' ');
  2. spacer(['a', 2, 3.4]); //=> 'a 2 3.4'
  3. R.join('|', [1, 2, 3]); //=> '1|2|3'

lastIndexOf


a → [a] → Number

Parameters

  • targetThe item to find.
  • xsThe array to search in.

Returns Number the index of the target, or -1 if the target is not found.

Added in v0.1.0

Returns the position of the last occurrence of an item in an array, or -1 if the item is not included in the array. R.equals is used to determine equality.

See also indexOf, findLastIndex.

  1. R.lastIndexOf(3, [-1,3,3,0,1,2,3,4]); //=> 6
  2. R.lastIndexOf(10, [1,2,3,4]); //=> -1

map


Functor f => (a → b) → f a → f b

Parameters

  • fnThe function to be called on every element of the input list.
  • listThe list to be iterated over.

Returns Array The new list.

Added in v0.1.0

Takes a function and a functor, applies the function to each of the functor’s values, and returns a functor of the same shape.

Ramda provides suitable map implementations for Array and Object, so this function may be applied to [1, 2, 3] or {x: 1, y: 2, z: 3}.

Dispatches to the map method of the second argument, if present.

Acts as a transducer if a transformer is given in list position.

Also treats functions as functors and will compose them together.

See also transduce, addIndex, pluck, project.

  1. const double = x => x * 2;
  2. R.map(double, [1, 2, 3]); //=> [2, 4, 6]
  3. R.map(double, {x: 1, y: 2, z: 3}); //=> {x: 2, y: 4, z: 6}

nth


Number → [a] → a | Undefined

Number → String → String | Undefined

Added in v0.1.0

Returns the nth element of the given list or string. If n is negative the element at index length + n is returned.

  1. const list = ['foo', 'bar', 'baz', 'quux'];
  2. R.nth(1, list); //=> 'bar'
  3. R.nth(-1, list); //=> 'quux'
  4. R.nth(-99, list); //=> undefined
  5. R.nth(2, 'abc'); //=> 'c'
  6. R.nth(3, 'abc'); //=> undefined

pluck


Functor f => k → f {k: v} → f v

Parameters

  • keyThe key name to pluck off of each object.
  • fThe array or functor to consider.

Returns Array The list of values for the given key.

Added in v0.1.0

Returns a new list by plucking the same named property off all objects in the list supplied.

pluck will work on any functor in addition to arrays, as it is equivalent to R.map(R.prop(k), f).

See also project, prop, props.

  1. var getAges = R.pluck('age');
  2. getAges([{name: 'fred', age: 29}, {name: 'wilma', age: 27}]); //=> [29, 27]
  3. R.pluck(0, [[1, 2], [3, 4]]); //=> [1, 3]
  4. R.pluck('val', {a: {val: 3}, b: {val: 5}}); //=> {a: 3, b: 5}

prepend


a → [a] → [a]

Parameters

  • elThe item to add to the head of the output list.
  • listThe array to add to the tail of the output list.

Returns Array A new array.

Added in v0.1.0

Returns a new list with the given element at the front, followed by the contents of the list.

See also append.

  1. R.prepend('fee', ['fi', 'fo', 'fum']); //=> ['fee', 'fi', 'fo', 'fum']

range


Number → Number → [Number]

Parameters

  • fromThe first number in the list.
  • toOne more than the last number in the list.

Returns Array The list of numbers in the set [a, b).

Added in v0.1.0

Returns a list of numbers from from (inclusive) to to (exclusive).

  1. R.range(1, 5); //=> [1, 2, 3, 4]
  2. R.range(50, 53); //=> [50, 51, 52]

reduce


((a, b) → a) → a → [b] → a

Parameters

  • fnThe iterator function. Receives two values, the accumulator and the current element from the array.
  • accThe accumulator value.
  • listThe list to iterate over.

Returns * The final, accumulated value.

Added in v0.1.0

Returns a single item by iterating through the list, successively calling the iterator function and passing it an accumulator value and the current value from the array, and then passing the result to the next call.

The iterator function receives two values: (acc, value). It may use R.reduced to shortcut the iteration.

The arguments’ order of reduceRight‘s iterator function is (value, acc).

Note: R.reduce does not skip deleted or unassigned indices (sparse arrays), unlike the native Array.prototype.reduce method. For more details on this behavior, see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce#Description

Be cautious of mutating and returning the accumulator. If you reuse it across invocations, it will continue to accumulate onto the same value. The general recommendation is to always return a new value. If you can’t do so for performance reasons, then be sure to reinitialize the accumulator on each invocation.

Dispatches to the reduce method of the third argument, if present. When doing so, it is up to the user to handle the R.reduced shortcuting, as this is not implemented by reduce.

See also reduced, addIndex, reduceRight.

  1. R.reduce(R.subtract, 0, [1, 2, 3, 4]) // => ((((0 - 1) - 2) - 3) - 4) = -10
  2. // - -10
  3. // / \ / \
  4. // - 4 -6 4
  5. // / \ / \
  6. // - 3 ==> -3 3
  7. // / \ / \
  8. // - 2 -1 2
  9. // / \ / \
  10. // 0 1 0 1

reduceRight


((a, b) → b) → b → [a] → b

Parameters

  • fnThe iterator function. Receives two values, the current element from the array and the accumulator.
  • accThe accumulator value.
  • listThe list to iterate over.

Returns * The final, accumulated value.

Added in v0.1.0

Returns a single item by iterating through the list, successively calling the iterator function and passing it an accumulator value and the current value from the array, and then passing the result to the next call.

Similar to reduce, except moves through the input list from the right to the left.

The iterator function receives two values: (value, acc), while the arguments’ order of reduce‘s iterator function is (acc, value). reduceRight may use reduced to short circuit the iteration.

Note: R.reduceRight does not skip deleted or unassigned indices (sparse arrays), unlike the native Array.prototype.reduceRight method. For more details on this behavior, see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight#Description

Be cautious of mutating and returning the accumulator. If you reuse it across invocations, it will continue to accumulate onto the same value. The general recommendation is to always return a new value. If you can’t do so for performance reasons, then be sure to reinitialize the accumulator on each invocation.

See also reduce, addIndex, reduced.

  1. R.reduceRight(R.subtract, 0, [1, 2, 3, 4]) // => (1 - (2 - (3 - (4 - 0)))) = -2
  2. // - -2
  3. // / \ / \
  4. // 1 - 1 3
  5. // / \ / \
  6. // 2 - ==> 2 -1
  7. // / \ / \
  8. // 3 - 3 4
  9. // / \ / \
  10. // 4 0 4 0

reject


Filterable f => (a → Boolean) → f a → f a

Parameters

  • pred
  • filterable

Returns Array

Added in v0.1.0

The complement of filter.

Acts as a transducer if a transformer is given in list position. Filterable objects include plain objects or any object that has a filter method such as Array.

See also filter, transduce, addIndex.

  1. const isOdd = (n) => n % 2 !== 0;
  2. R.reject(isOdd, [1, 2, 3, 4]); //=> [2, 4]
  3. R.reject(isOdd, {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, d: 4}

reverse


[a] → [a]

String → String

Added in v0.1.0

Returns a new list or string with the elements or characters in reverse order.

  1. R.reverse([1, 2, 3]); //=> [3, 2, 1]
  2. R.reverse([1, 2]); //=> [2, 1]
  3. R.reverse([1]); //=> [1]
  4. R.reverse([]); //=> []
  5. R.reverse('abc'); //=> 'cba'
  6. R.reverse('ab'); //=> 'ba'
  7. R.reverse('a'); //=> 'a'
  8. R.reverse(''); //=> ''

sort


((a, a) → Number) → [a] → [a]

Parameters

  • comparatorA sorting function :: a -> b -> Int
  • listThe list to sort

Returns Array a new array with its elements sorted by the comparator function.

Added in v0.1.0

Returns a copy of the list, sorted according to the comparator function, which should accept two values at a time and return a negative number if the first value is smaller, a positive number if it’s larger, and zero if they are equal. Please note that this is a copy of the list. It does not modify the original.

See also ascend, descend.

  1. const diff = function(a, b) { return a - b; };
  2. R.sort(diff, [4,2,7,5]); //=> [2, 4, 5, 7]

tail


[a] → [a]

String → String

Added in v0.1.0

Returns all but the first element of the given list or string (or object with a tail method).

Dispatches to the slice method of the first argument, if present.

See also head, init, last.

  1. R.tail([1, 2, 3]); //=> [2, 3]
  2. R.tail([1, 2]); //=> [2]
  3. R.tail([1]); //=> []
  4. R.tail([]); //=> []
  5. R.tail('abc'); //=> 'bc'
  6. R.tail('ab'); //=> 'b'
  7. R.tail('a'); //=> ''
  8. R.tail(''); //=> ''

take


Number → [a] → [a]

Number → String → String

Added in v0.1.0

Returns the first n elements of the given list, string, or transducer/transformer (or object with a take method).

Dispatches to the take method of the second argument, if present.

See also drop.

  1. R.take(1, ['foo', 'bar', 'baz']); //=> ['foo']
  2. R.take(2, ['foo', 'bar', 'baz']); //=> ['foo', 'bar']
  3. R.take(3, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz']
  4. R.take(4, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz']
  5. R.take(3, 'ramda'); //=> 'ram'
  6. const personnel = [
  7. 'Dave Brubeck',
  8. 'Paul Desmond',
  9. 'Eugene Wright',
  10. 'Joe Morello',
  11. 'Gerry Mulligan',
  12. 'Bob Bates',
  13. 'Joe Dodge',
  14. 'Ron Crotty'
  15. ];
  16. const takeFive = R.take(5);
  17. takeFive(personnel);
  18. //=> ['Dave Brubeck', 'Paul Desmond', 'Eugene Wright', 'Joe Morello', 'Gerry Mulligan']

takeWhile


(a → Boolean) → [a] → [a]

(a → Boolean) → String → String

Parameters

  • fnThe function called per iteration.
  • xsThe collection to iterate over.

Returns Array A new array.

Added in v0.1.0

Returns a new list containing the first n elements of a given list, passing each value to the supplied predicate function, and terminating when the predicate function returns false. Excludes the element that caused the predicate function to fail. The predicate function is passed one argument: (value).

Dispatches to the takeWhile method of the second argument, if present.

Acts as a transducer if a transformer is given in list position.

See also dropWhile, transduce, addIndex.

  1. const isNotFour = x => x !== 4;
  2. R.takeWhile(isNotFour, [1, 2, 3, 4, 3, 2, 1]); //=> [1, 2, 3]
  3. R.takeWhile(x => x !== 'd' , 'Ramda'); //=> 'Ram'

findLast


(a → Boolean) → [a] → a | undefined

Parameters

  • fnThe predicate function used to determine if the element is the desired one.
  • listThe array to consider.

Returns Object The element found, or undefined.

Added in v0.1.1

Returns the last element of the list which matches the predicate, or undefined if no element matches.

Acts as a transducer if a transformer is given in list position.

See also transduce.

  1. const xs = [{a: 1, b: 0}, {a:1, b: 1}];
  2. R.findLast(R.propEq(1, 'a'))(xs); //=> {a: 1, b: 1}
  3. R.findLast(R.propEq(4, 'a'))(xs); //=> undefined

findLastIndex


(a → Boolean) → [a] → Number

Parameters

  • fnThe predicate function used to determine if the element is the desired one.
  • listThe array to consider.

Returns Number The index of the element found, or -1.

Added in v0.1.1

Returns the index of the last element of the list which matches the predicate, or -1 if no element matches.

Acts as a transducer if a transformer is given in list position.

See also transduce, lastIndexOf.

  1. const xs = [{a: 1, b: 0}, {a:1, b: 1}];
  2. R.findLastIndex(R.propEq(1, 'a'))(xs); //=> 1
  3. R.findLastIndex(R.propEq(4, 'a'))(xs); //=> -1

forEach


(a → *) → [a] → [a]

Parameters

  • fnThe function to invoke. Receives one argument, value.
  • listThe list to iterate over.

Returns Array The original list.

Added in v0.1.1

Iterate over an input list, calling a provided function fn for each element in the list.

fn receives one argument: (value).

Note: R.forEach does not skip deleted or unassigned indices (sparse arrays), unlike the native Array.prototype.forEach method. For more details on this behavior, see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach#Description

Also note that, unlike Array.prototype.forEach, Ramda’s forEach returns the original array. In some libraries this function is named each.

Dispatches to the forEach method of the second argument, if present.

See also addIndex.

  1. const printXPlusFive = x => console.log(x + 5);
  2. R.forEach(printXPlusFive, [1, 2, 3]); //=> [1, 2, 3]
  3. // logs 6
  4. // logs 7
  5. // logs 8

repeat


a → n → [a]

Parameters

  • valueThe value to repeat.
  • nThe desired size of the output list.

Returns Array A new array containing n values.

Added in v0.1.1

Returns a fixed list of size n containing a specified identical value.

See also times.

  1. R.repeat('hi', 5); //=> ['hi', 'hi', 'hi', 'hi', 'hi']
  2. const obj = {};
  3. const repeatedObjs = R.repeat(obj, 5); //=> [{}, {}, {}, {}, {}]
  4. repeatedObjs[0] === repeatedObjs[1]; //=> true

findIndex


(a → Boolean) → [a] → Number

Parameters

  • fnThe predicate function used to determine if the element is the desired one.
  • listThe array to consider.

Returns Number The index of the element found, or -1.

Added in v0.1.1

Returns the index of the first element of the list which matches the predicate, or -1 if no element matches.

Acts as a transducer if a transformer is given in list position.

See also transduce, indexOf.

  1. const xs = [{a: 1}, {a: 2}, {a: 3}];
  2. R.findIndex(R.propEq(2, 'a'))(xs); //=> 1
  3. R.findIndex(R.propEq(4, 'a'))(xs); //=> -1

last


[a] → a | Undefined

String → String | Undefined

Added in v0.1.4

Returns the last element of the given list or string.

See also init, head, tail.

  1. R.last(['fi', 'fo', 'fum']); //=> 'fum'
  2. R.last([]); //=> undefined
  3. R.last('abc'); //=> 'c'
  4. R.last(''); //=> undefined

partition


Filterable f => (a → Boolean) → f a → [f a, f a]

Parameters

  • predA predicate to determine which side the element belongs to.
  • filterablethe list (or other filterable) to partition.

Returns Array An array, containing first the subset of elements that satisfy the predicate, and second the subset of elements that do not satisfy.

Added in v0.1.4

Takes a predicate and a list or other Filterable object and returns the pair of filterable objects of the same type of elements which do and do not satisfy, the predicate, respectively. Filterable objects include plain objects or any object that has a filter method such as Array.

See also filter, reject.

  1. R.partition(R.includes('s'), ['sss', 'ttt', 'foo', 'bars']);
  2. // => [ [ 'sss', 'bars' ], [ 'ttt', 'foo' ] ]
  3. R.partition(R.includes('s'), { a: 'sss', b: 'ttt', foo: 'bars' });
  4. // => [ { a: 'sss', foo: 'bars' }, { b: 'ttt' } ]

slice


Number → Number → [a] → [a]

Number → Number → String → String

Parameters

  • fromIndexThe start index (inclusive).
  • toIndexThe end index (exclusive).
  • list

Returns *

Added in v0.1.4

Returns the elements of the given list or string (or object with a slice method) from fromIndex (inclusive) to toIndex (exclusive).

Dispatches to the slice method of the third argument, if present.

  1. R.slice(1, 3, ['a', 'b', 'c', 'd']); //=> ['b', 'c']
  2. R.slice(1, Infinity, ['a', 'b', 'c', 'd']); //=> ['b', 'c', 'd']
  3. R.slice(0, -1, ['a', 'b', 'c', 'd']); //=> ['a', 'b', 'c']
  4. R.slice(-3, -1, ['a', 'b', 'c', 'd']); //=> ['b', 'c']
  5. R.slice(0, 3, 'ramda'); //=> 'ram'

uniqWith


((a, a) → Boolean) → [a] → [a]

Parameters

  • predA predicate used to test whether two items are equal.
  • listThe array to consider.

Returns Array The list of unique items.

Added in v0.2.0

Returns a new list containing only one copy of each element in the original list, based upon the value returned by applying the supplied predicate to two list elements. Prefers the first item if two items compare equal based on the predicate.

Acts as a transducer if a transformer is given in list position.

  1. const strEq = R.eqBy(String);
  2. R.uniqWith(strEq)([1, '1', 2, 1]); //=> [1, 2]
  3. R.uniqWith(strEq)([{}, {}]); //=> [{}]
  4. R.uniqWith(strEq)([1, '1', 1]); //=> [1]
  5. R.uniqWith(strEq)(['1', 1, 1]); //=> ['1']

insert


Number → a → [a] → [a]

Parameters

  • indexThe position to insert the element
  • eltThe element to insert into the Array
  • listThe list to insert into

Returns Array A new Array with elt inserted at index.

Added in v0.2.2

Inserts the supplied element into the list, at the specified index. Note that this is not destructive: it returns a copy of the list with the changes. No lists have been harmed in the application of this function.

  1. R.insert(2, 'x', [1,2,3,4]); //=> [1,2,'x',3,4]

remove


Number → Number → [a] → [a]

Parameters

  • startThe position to start removing elements
  • countThe number of elements to remove
  • listThe list to remove from

Returns Array A new Array with count elements from start removed.

Added in v0.2.2

Removes the sub-list of list starting at index start and containing count elements. Note that this is not destructive: it returns a copy of the list with the changes. No lists have been harmed in the application of this function.

See also without.

  1. R.remove(2, 3, [1,2,3,4,5,6,7,8]); //=> [1,2,6,7,8]

times


(Number → a) → Number → [a]

Parameters

  • fnThe function to invoke. Passed one argument, the current value of n.
  • nA value between 0 and n - 1. Increments after each function call.

Returns Array An array containing the return values of all calls to fn.

Added in v0.2.3

Calls an input function n times, returning an array containing the results of those function calls.

fn is passed one argument: The current value of n, which begins at 0 and is gradually incremented to n - 1.

See also repeat.

  1. R.times(R.identity, 5); //=> [0, 1, 2, 3, 4]