__ Function

Added in v0.6.0

A special placeholder value used to specify "gaps" within curried functions, allowing partial application of any combination of arguments, regardless of their positions.

If g is a curried ternary function and _ is R.__, the following are equivalent:

  • g(1, 2, 3)
  • g(_, 2, 3)(1)
  • g(_, _, 3)(1)(2)
  • g(_, _, 3)(1, 2)
  • g(_, 2, _)(1, 3)
  • g(_, 2)(1)(3)
  • g(_, 2)(1, 3)
  • g(_, 2)(_, 3)(1)
var greet = R.replace('{name}', R.__, 'Hello, {name}!');
greet('Alice'); //=> 'Hello, Alice!'

add Math

Number → Number → Number
Parameters
  • Number a
  • Number b
Returns Number

Added in v0.1.0

Adds two numbers. Equivalent to a + b but curried.

See also subtract.
R.add(2, 3);       //=>  5
R.add(7)(10);      //=> 17

addIndex Function

((a … → b) … → [a] → *) → (a …, Int, [a] → b) … → [a] → *)
Parameters
  • function fn

    A list iteration function that does not pass index or list to its callback

Returns function

An altered list iteration function that passes (item, index, list) to its callback

Added in v0.15.0

Creates a new list iteration function from an existing one by adding two new parameters to its callback function: the current index, and the entire list.

This would turn, for instance, Ramda's simple map function into one that more closely resembles Array.prototype.map. Note that this will only work for functions in which the iteration callback function is the first parameter, and where the list is the last parameter. (This latter might be unimportant if the list parameter is not used.)

var mapIndexed = R.addIndex(R.map);
mapIndexed((val, idx) => idx + '-' + val, ['f', 'o', 'o', 'b', 'a', 'r']);
//=> ['0-f', '1-o', '2-o', '3-b', '4-a', '5-r']

adjust List

(a → a) → Number → [a] → [a]
Parameters
  • function fn

    The function to apply.

  • Number idx

    The index.

  • Array list

    An array-like object whose value at the supplied index will be replaced.

Returns Array

A copy of the supplied array-like object with the element at index idx replaced with the value returned by applying fn to the existing element.

Added in v0.14.0

Applies a function to the value at the given index of an array, returning a new copy of the array with the element at the given index replaced with the result of the function application.

See also update.
R.adjust(R.add(10), 1, [0, 1, 2]);     //=> [0, 11, 2]
R.adjust(R.add(10))(1)([0, 1, 2]);     //=> [0, 11, 2]

all List

(a → Boolean) → [a] → Boolean
Parameters
  • function fn

    The predicate function.

  • Array list

    The 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.
var lessThan2 = R.flip(R.lt)(2);
var lessThan3 = R.flip(R.lt)(3);
R.all(lessThan2)([1, 2]); //=> false
R.all(lessThan3)([1, 2]); //=> true

allPass Logic

[(*… → Boolean)] → (*… → Boolean)
Parameters
  • Array preds
Returns function

Added in v0.9.0

Takes a list of predicates and returns a predicate that returns true for a given list of arguments if every one of the provided predicates is satisfied by those arguments.

The function returned is a curried function whose arity matches that of the highest-arity predicate.

See also anyPass.
var isQueen = R.propEq('rank', 'Q');
var isSpade = R.propEq('suit', '♠︎');
var isQueenOfSpades = R.allPass([isQueen, isSpade]);

isQueenOfSpades({rank: 'Q', suit: '♣︎'}); //=> false
isQueenOfSpades({rank: 'Q', suit: '♠︎'}); //=> true

allUniq List

[a] → Boolean
Parameters
  • Array list

    The array to consider.

Returns Boolean

true if all elements are unique, else false.

Added in v0.18.0

Returns true if all elements are unique, in R.equals terms, otherwise false.

R.allUniq(['1', 1]); //=> true
R.allUniq([1, 1]);   //=> false
R.allUniq([[42], [42]]); //=> false

always Function

a → (* → a)
Parameters
  • * val

    The value to wrap in a function

Returns function

A Function :: * -> val.

Added in v0.1.0

Returns a function that always returns the given value. Note that for non-primitives the value returned is a reference to the original value.

This function is known as const, constant, or K (for K combinator) in other languages and libraries.

var t = R.always('Tee');
t(); //=> 'Tee'

and Logic

* → * → *
Parameters
  • Boolean a

    A boolean value

  • Boolean b

    A boolean value

Returns Boolean

true if both arguments are true, false otherwise

Added in v0.1.0

Returns true if both arguments are true; false otherwise.

See also both.
R.and(true, true); //=> true
R.and(true, false); //=> false
R.and(false, true); //=> false
R.and(false, false); //=> false

any List

(a → Boolean) → [a] → Boolean
Parameters
  • function fn

    The predicate function.

  • Array list

    The 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 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.
var lessThan0 = R.flip(R.lt)(0);
var lessThan2 = R.flip(R.lt)(2);
R.any(lessThan0)([1, 2]); //=> false
R.any(lessThan2)([1, 2]); //=> true

anyPass Logic

[(*… → Boolean)] → (*… → Boolean)
Parameters
  • Array preds
Returns function

Added in v0.9.0

Takes a list of predicates and returns a predicate that returns true for a given list of arguments if at least one of the provided predicates is satisfied by those arguments.

The function returned is a curried function whose arity matches that of the highest-arity predicate.

See also allPass.
var gte = R.anyPass([R.gt, R.equals]);

gte(3, 2); //=> true
gte(2, 2); //=> true
gte(2, 3); //=> false

ap Function

[f] → [a] → [f a]
Parameters
  • Array fns

    An array of functions

  • Array vs

    An array of values

Returns Array

An array of results of applying each of fns to all of vs in turn.

Added in v0.3.0

ap applies a list of functions to a list of values.

Dispatches to the ap method of the second argument, if present. Also treats functions as applicatives.

R.ap([R.multiply(2), R.add(3)], [1,2,3]); //=> [2, 4, 6, 4, 5, 6]

aperture List

Number → [a] → [[a]]
Parameters
  • Number n

    The size of the tuples to create

  • Array list

    The list to split into n-tuples

Returns Array

The new list.

Added in v0.12.0

Returns a new list, composed of n-tuples of consecutive elements If n is greater than the length of the list, an empty list is returned.

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

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

See also transduce.
R.aperture(2, [1, 2, 3, 4, 5]); //=> [[1, 2], [2, 3], [3, 4], [4, 5]]
R.aperture(3, [1, 2, 3, 4, 5]); //=> [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
R.aperture(7, [1, 2, 3, 4, 5]); //=> []

append List

a → [a] → [a]
Parameters
  • * el

    The element to add to the end of the new list.

  • Array list

    The list whose contents will be added to the beginning of the output list.

Returns Array

A new list containing the contents 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.
R.append('tests', ['write', 'more']); //=> ['write', 'more', 'tests']
R.append('tests', []); //=> ['tests']
R.append(['tests'], ['write', 'more']); //=> ['write', 'more', ['tests']]

apply Function

(*… → a) → [*] → a
Parameters
  • function fn
  • Array args
Returns *

Added in v0.7.0

Applies function fn to the argument list args. This is useful for creating a fixed-arity function from a variadic function. fn should be a bound function if context is significant.

See also call, unapply.
var nums = [1, 2, 3, -99, 42, 6, 7];
R.apply(Math.max, nums); //=> 42

assoc Object

String → a → {k: v} → {k: v}
Parameters
  • String prop

    the property name to set

  • * val

    the new value

  • Object obj

    the object to clone

Returns Object

a new object similar to the original except for the specified property.

Added in v0.8.0

Makes a shallow clone of an object, setting or overriding the specified property with the given value. Note that this copies and flattens prototype properties onto the new object as well. All non-primitive properties are copied by reference.

See also dissoc.
R.assoc('c', 3, {a: 1, b: 2}); //=> {a: 1, b: 2, c: 3}

assocPath Object

[String] → a → {k: v} → {k: v}
Parameters
  • Array path

    the path to set

  • * val

    the new value

  • Object obj

    the object to clone

Returns Object

a new object similar to the original except along the specified path.

Added in v0.8.0

Makes a shallow clone of an object, setting or overriding the nodes required to create the given path, and placing the specific value at the tail end of that path. Note that this copies and flattens prototype properties onto the new object as well. All non-primitive properties are copied by reference.

See also dissocPath.
R.assocPath(['a', 'b', 'c'], 42, {a: {b: {c: 0}}}); //=> {a: {b: {c: 42}}}

binary Function

(* → c) → (a, b → c)
Parameters
  • function fn

    The function to wrap.

Returns function

A new function wrapping fn. The new function is guaranteed to be of arity 2.

Added in v0.2.0

Wraps a function of any arity (including nullary) in a function that accepts exactly 2 parameters. Any extraneous parameters will not be passed to the supplied function.

var takesThreeArgs = function(a, b, c) {
  return [a, b, c];
};
takesThreeArgs.length; //=> 3
takesThreeArgs(1, 2, 3); //=> [1, 2, 3]

var takesTwoArgs = R.binary(takesThreeArgs);
takesTwoArgs.length; //=> 2
// Only 2 arguments are passed to the wrapped function
takesTwoArgs(1, 2, 3); //=> [1, 2, undefined]

bind Function

(* → *) → {*} → (* → *)
Parameters
  • function fn

    The function to bind to context

  • Object thisObj

    The context to bind fn to

Returns function

A function that will execute in the context of thisObj.

Added in v0.6.0

Creates a function that is bound to a context. Note: R.bind does not provide the additional argument-binding capabilities of Function.prototype.bind.

See also partial.

both Logic

(*… → Boolean) → (*… → Boolean) → (*… → Boolean)
Parameters
  • function f

    a predicate

  • function g

    another predicate

Returns function

a function that applies its arguments to f and g and &&s their outputs together.

Added in v0.12.0

A function wrapping calls to the two functions in an && operation, returning the result of the first function if it is false-y and the result of the second function otherwise. Note that this is short-circuited, meaning that the second function will not be invoked if the first returns a false-y value.

See also and.
var gt10 = x => x > 10;
var even = x => x % 2 === 0;
var f = R.both(gt10, even);
f(100); //=> true
f(101); //=> false

call Function

(*… → a),*… → a
Parameters
  • function fn

    The function to apply to the remaining arguments.

  • * args

    Any number of positional arguments.

Returns *

Added in v0.9.0

Returns the result of calling its first argument with the remaining arguments. This is occasionally useful as a converging function for R.converge: the left branch can produce a function while the right branch produces a value to be passed to that function as an argument.

See also apply.
var indentN = R.pipe(R.times(R.always(' ')),
                     R.join(''),
                     R.replace(/^(?!$)/gm));

var format = R.converge(R.call, [
                            R.pipe(R.prop('indent'), indentN),
                            R.prop('value')
                        ]);

format({indent: 2, value: 'foo\nbar\nbaz\n'}); //=> '  foo\n  bar\n  baz\n'

chain List

(a → [b]) → [a] → [b]
Parameters
  • function fn
  • Array list
Returns Array

Added in v0.3.0

chain maps a function over a list and concatenates the results. chain is also known as flatMap in some libraries

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

var duplicate = n => [n, n];
R.chain(duplicate, [1, 2, 3]); //=> [1, 1, 2, 2, 3, 3]

clone Object

{*} → {*}
Parameters
  • * value

    The object or array to clone

Returns *

A new object or array.

Added in v0.1.0

Creates a deep copy of the value which may contain (nested) Arrays and Objects, Numbers, Strings, Booleans and Dates. Functions are not copied, but assigned by their reference.

Dispatches to a clone method if present.

var objects = [{}, {}, {}];
var objectsClone = R.clone(objects);
objects[0] === objectsClone[0]; //=> false

commute List

Deprecated since v0.19.0
Functor f => (x → f x) → [f a] → f [a]
Parameters
  • function of

    A function that returns the data type to return

  • Array list

    An array of functors of the same type

Returns *

Added in v0.8.0

Turns a list of Functors into a Functor of a list.

See also sequence.
R.commute(R.of, [[1], [2, 3]]);   //=> [[1, 2], [1, 3]]
R.commute(R.of, [[1, 2], [3]]);   //=> [[1, 3], [2, 3]]
R.commute(R.of, [[1], [2], [3]]); //=> [[1, 2, 3]]
R.commute(Maybe.of, [Just(1), Just(2), Just(3)]);   //=> Just([1, 2, 3])
R.commute(Maybe.of, [Just(1), Just(2), Nothing()]); //=> Nothing()

commuteMap List

Deprecated since v0.19.0
Functor f => (a → f b) → (x → f x) → [a] → f [b]
Parameters
  • function fn

    The transformation function

  • function of

    A function that returns the data type to return

  • Array list

    An array of functors of the same type

Returns *

Added in v0.8.0

Turns a list of Functors into a Functor of a list, applying a mapping function to the elements of the list along the way.

See also traverse.
var add10 = R.map(R.add(10));
R.commuteMap(add10, R.of, [[1], [2, 3]]);   //=> [[11, 12], [11, 13]]
R.commuteMap(add10, R.of, [[1, 2], [3]]);   //=> [[11, 13], [12, 13]]
R.commuteMap(add10, R.of, [[1], [2], [3]]); //=> [[11, 12, 13]]
R.commuteMap(add10, Maybe.of, [Just(1), Just(2), Just(3)]);   //=> Just([11, 12, 13])
R.commuteMap(add10, Maybe.of, [Just(1), Just(2), Nothing()]); //=> Nothing()

var fetch = url => Future((rej, res) => http.get(url, res).on('error', rej));
R.commuteMap(fetch, Future.of, [
  'http://ramdajs.com',
  'http://github.com/ramda'
]); //=> Future([IncomingMessage, IncomingMessage])

comparator Function

(a, b → Boolean) → (a, b → Number)
Parameters
  • function pred

    A predicate function of arity two.

Returns function

A Function :: a -> b -> Int that returns -1 if a < b, 1 if b < a, otherwise 0.

Added in v0.1.0

Makes a comparator function out of a function that reports whether the first element is less than the second.

var cmp = R.comparator((a, b) => a.age < b.age);
var people = [
  // ...
];
R.sort(cmp, people);

complement Logic

(*… → *) → (*… → Boolean)
Parameters
  • function f
Returns function

Added in v0.12.0

Takes a function f and returns a function g such that:

  • applying g to zero or more arguments will give true if applying the same arguments to f gives a logical false value; and

  • applying g to zero or more arguments will give false if applying the same arguments to f gives a logical true value.

R.complement will work on all other functors as well.

See also not.
var isEven = n => n % 2 === 0;
var isOdd = R.complement(isEven);
isOdd(21); //=> true
isOdd(42); //=> false

compose Function

((y → z), (x → y), …, (o → p), ((a, b, …, n) → o)) → ((a, b, …, n) → z)
Parameters
  • function functions
Returns function

Added in v0.1.0

Performs right-to-left function composition. The rightmost function may have any arity; the remaining functions must be unary.

See also pipe.
var f = R.compose(R.inc, R.negate, Math.pow);

f(3, 4); // -(3^4) + 1

composeK Function

Chain m => ((y → m z), (x → m y), …, (a → m b)) → (m a → m z)
Parameters
  • function
Returns function

Added in v0.16.0

Returns the right-to-left Kleisli composition of the provided functions, each of which must return a value of a type supported by chain.

R.composeK(h, g, f) is equivalent to R.compose(R.chain(h), R.chain(g), R.chain(f)).

See also pipeK.
//  parseJson :: String -> Maybe *
//  get :: String -> Object -> Maybe *

//  getStateCode :: Maybe String -> Maybe String
var getStateCode = R.composeK(
  R.compose(Maybe.of, R.toUpper),
  get('state'),
  get('address'),
  get('user'),
  parseJson
);

getStateCode(Maybe.of('{"user":{"address":{"state":"ny"}}}'));
//=> Just('NY')
getStateCode(Maybe.of('[Invalid JSON]'));
//=> Nothing()

composeP Function

((y → Promise z), (x → Promise y), …, (a → Promise b)) → (a → Promise z)
Parameters
  • function functions
Returns function

Added in v0.10.0

Performs right-to-left composition of one or more Promise-returning functions. The rightmost function may have any arity; the remaining functions must be unary.

See also pipeP.
//  followersForUser :: String -> Promise [User]
var followersForUser = R.composeP(db.getFollowers, db.getUserById);

concat List

[a] → [a] → [a]
String → String → String
Parameters
  • Array a
  • Array b
Returns Array

Added in v0.1.0

Returns the result of concatenating the given lists or strings.

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

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

cond Logic

[[(*… → Boolean),(*… → *)]] → (*… → *)
Parameters
  • Array pairs
Returns function

Added in v0.6.0

Returns a function, fn, which encapsulates if/else-if/else logic. R.cond takes a list of [predicate, transform] pairs. All of the arguments to fn are applied to each of the predicates in turn until one returns a "truthy" value, at which point fn returns the result of applying its arguments to the corresponding transformer. If none of the predicates matches, fn returns undefined.

var fn = R.cond([
  [R.equals(0),   R.always('water freezes at 0°C')],
  [R.equals(100), R.always('water boils at 100°C')],
  [R.T,           temp => 'nothing special happens at ' + temp + '°C']
]);
fn(0); //=> 'water freezes at 0°C'
fn(50); //=> 'nothing special happens at 50°C'
fn(100); //=> 'water boils at 100°C'

construct Function

(* → {*}) → (* → {*})
Parameters
  • function Fn

    The constructor function to wrap.

Returns function

A wrapped, curried constructor function.

Added in v0.1.0

Wraps a constructor function inside a curried function that can be called with the same arguments and returns the same type.

// Constructor function
var Widget = config => {
  // ...
};
Widget.prototype = {
  // ...
};
var allConfigs = [
  // ...
];
R.map(R.construct(Widget), allConfigs); // a list of Widgets

constructN Function

Number → (* → {*}) → (* → {*})
Parameters
  • Number n

    The arity of the constructor function.

  • function Fn

    The constructor function to wrap.

Returns function

A wrapped, curried constructor function.

Added in v0.4.0

Wraps a constructor function inside a curried function that can be called with the same arguments and returns the same type. The arity of the function returned is specified to allow using variadic constructor functions.

// Variadic constructor function
var Widget = () => {
  this.children = Array.prototype.slice.call(arguments);
  // ...
};
Widget.prototype = {
  // ...
};
var allConfigs = [
  // ...
];
R.map(R.constructN(1, Widget), allConfigs); // a list of Widgets

contains List

a → [a] → Boolean
Parameters
  • Object a

    The item to compare against.

  • Array list

    The array to consider.

Returns Boolean

true if the item is in the list, false otherwise.

Added in v0.1.0

Returns true if the specified value is equal, in R.equals terms, to at least one element of the given list; false otherwise.

See also any.
R.contains(3, [1, 2, 3]); //=> true
R.contains(4, [1, 2, 3]); //=> false
R.contains([42], [[42]]); //=> true

converge Function

(x1 → x2 → … → z) → [(a → b → … → x1), (a → b → … → x2), …] → (a → b → … → z)
Parameters
  • function after

    A function. after will be invoked with the return values of fn1 and fn2 as its arguments.

  • Array functions

    A list of functions.

Returns function

A new function.

Added in v0.4.2

Accepts a converging function and a list of branching functions and returns a new function. When invoked, this new function is applied to some arguments, each branching function is applied to those same arguments. The results of each branching function are passed as arguments to the converging function to produce the return value.

var add = (a, b) => a + b;
var multiply = (a, b) => a * b;
var subtract = (a, b) => a - b;

//≅ multiply( add(1, 2), subtract(1, 2) );
R.converge(multiply, [add, subtract])(1, 2); //=> -3

var add3 = (a, b, c) => a + b + c;
R.converge(add3, [multiply, add, subtract])(1, 2); //=> 4

countBy Relation

(a → String) → [a] → {*}
Parameters
  • function fn

    The function used to map values to keys.

  • Array list

    The list to count elements from.

Returns Object

An object mapping keys to number of occurrences in the list.

Added in v0.1.0

Counts the elements of a list according to how many match each value of a key generated by the supplied function. Returns an object mapping the keys produced by fn to the number of occurrences in the list. Note that all keys are coerced to strings because of how JavaScript objects work.

var numbers = [1.0, 1.1, 1.2, 2.0, 3.0, 2.2];
var letters = R.split('', 'abcABCaaaBBc');
R.countBy(Math.floor)(numbers);    //=> {'1': 3, '2': 2, '3': 1}
R.countBy(R.toLower)(letters);   //=> {'a': 5, 'b': 4, 'c': 3}

curry Function

(* → a) → (* → a)
Parameters
  • function fn

    The function to curry.

Returns function

A new, curried function.

Added in v0.1.0

Returns a curried equivalent of the provided function. The curried function has two unusual capabilities. First, its arguments needn't be provided one at a time. If f is a ternary function and g is R.curry(f), the following are equivalent:

  • g(1)(2)(3)
  • g(1)(2, 3)
  • g(1, 2)(3)
  • g(1, 2, 3)

Secondly, the special placeholder value R.__ may be used to specify "gaps", allowing partial application of any combination of arguments, regardless of their positions. If g is as above and _ is R.__, the following are equivalent:

  • g(1, 2, 3)
  • g(_, 2, 3)(1)
  • g(_, _, 3)(1)(2)
  • g(_, _, 3)(1, 2)
  • g(_, 2)(1)(3)
  • g(_, 2)(1, 3)
  • g(_, 2)(_, 3)(1)
See also curryN.
var addFourNumbers = (a, b, c, d) => a + b + c + d;

var curriedAddFourNumbers = R.curry(addFourNumbers);
var f = curriedAddFourNumbers(1, 2);
var g = f(3);
g(4); //=> 10

curryN Function

Number → (* → a) → (* → a)
Parameters
  • Number length

    The arity for the returned function.

  • function fn

    The function to curry.

Returns function

A new, curried function.

Added in v0.5.0

Returns a curried equivalent of the provided function, with the specified arity. The curried function has two unusual capabilities. First, its arguments needn't be provided one at a time. If g is R.curryN(3, f), the following are equivalent:

  • g(1)(2)(3)
  • g(1)(2, 3)
  • g(1, 2)(3)
  • g(1, 2, 3)

Secondly, the special placeholder value R.__ may be used to specify "gaps", allowing partial application of any combination of arguments, regardless of their positions. If g is as above and _ is R.__, the following are equivalent:

  • g(1, 2, 3)
  • g(_, 2, 3)(1)
  • g(_, _, 3)(1)(2)
  • g(_, _, 3)(1, 2)
  • g(_, 2)(1)(3)
  • g(_, 2)(1, 3)
  • g(_, 2)(_, 3)(1)
See also curry.
var sumArgs = (...args) => R.sum(args);

var curriedAddFourNumbers = R.curryN(4, sumArgs);
var f = curriedAddFourNumbers(1, 2);
var g = f(3);
g(4); //=> 10

dec Math

Number → Number
Parameters
  • Number n
Returns Number

Added in v0.9.0

Decrements its argument.

See also inc.
R.dec(42); //=> 41

defaultTo Logic

a → b → a | b
Parameters
  • a val

    The default value.

  • b val

    The value to return if it is not null or undefined

Returns *

The the second value or the default value

Added in v0.10.0

Returns the second argument if it is not null, undefined or NaN otherwise the first argument is returned.

var defaultTo42 = R.defaultTo(42);

defaultTo42(null);  //=> 42
defaultTo42(undefined);  //=> 42
defaultTo42('Ramda');  //=> 'Ramda'
defaultTo42(parseInt('string')); //=> 42

difference Relation

[*] → [*] → [*]
Parameters
  • Array list1

    The first list.

  • Array list2

    The second list.

Returns Array

The elements in list1 that are not in list2.

Added in v0.1.0

Finds the set (i.e. no duplicates) of all elements in the first list not contained in the second list.

See also differenceWith.
R.difference([1,2,3,4], [7,6,5,4,3]); //=> [1,2]
R.difference([7,6,5,4,3], [1,2,3,4]); //=> [7,6,5]

differenceWith Relation

(a → a → Boolean) → [*] → [*] → [*]
Parameters
  • function pred

    A predicate used to test whether two items are equal.

  • Array list1

    The first list.

  • Array list2

    The second list.

Returns Array

The elements in list1 that are not in list2.

Added in v0.1.0

Finds the set (i.e. no duplicates) of all elements in the first list not contained in the second list. Duplication is determined according to the value returned by applying the supplied predicate to two list elements.

See also difference.
function cmp(x, y) => x.a === y.a;
var l1 = [{a: 1}, {a: 2}, {a: 3}];
var l2 = [{a: 3}, {a: 4}];
R.differenceWith(cmp, l1, l2); //=> [{a: 1}, {a: 2}]

dissoc Object

String → {k: v} → {k: v}
Parameters
  • String prop

    the name of the property to dissociate

  • Object obj

    the object to clone

Returns Object

a new object similar to the original but without the specified property

Added in v0.10.0

Returns a new object that does not contain a prop property.

See also assoc.
R.dissoc('b', {a: 1, b: 2, c: 3}); //=> {a: 1, c: 3}

dissocPath Object

[String] → {k: v} → {k: v}
Parameters
  • Array path

    the path to set

  • Object obj

    the object to clone

Returns Object

a new object without the property at path

Added in v0.11.0

Makes a shallow clone of an object, omitting the property at the given path. Note that this copies and flattens prototype properties onto the new object as well. All non-primitive properties are copied by reference.

See also assocPath.
R.dissocPath(['a', 'b', 'c'], {a: {b: {c: 42}}}); //=> {a: {b: {}}}

divide Math

Number → Number → Number
Parameters
  • Number a

    The first value.

  • Number b

    The second value.

Returns Number

The result of a / b.

Added in v0.1.0

Divides two numbers. Equivalent to a / b.

See also multiply.
R.divide(71, 100); //=> 0.71

var half = R.divide(R.__, 2);
half(42); //=> 21

var reciprocal = R.divide(1);
reciprocal(4);   //=> 0.25

drop List

Number → [a] → [a]
Number → String → String
Parameters
  • Number n
  • * list
Returns *

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.
R.drop(1, ['foo', 'bar', 'baz']); //=> ['bar', 'baz']
R.drop(2, ['foo', 'bar', 'baz']); //=> ['baz']
R.drop(3, ['foo', 'bar', 'baz']); //=> []
R.drop(4, ['foo', 'bar', 'baz']); //=> []
R.drop(3, 'ramda');               //=> 'da'

dropLast List

Number → [a] → [a]
Number → String → String
Parameters
  • Number n

    The number of elements of xs to skip.

  • Array xs

    The collection to consider.

Returns Array

Added in v0.16.0

Returns a list containing all but the last n elements of the given list.

See also takeLast.
R.dropLast(1, ['foo', 'bar', 'baz']); //=> ['foo', 'bar']
R.dropLast(2, ['foo', 'bar', 'baz']); //=> ['foo']
R.dropLast(3, ['foo', 'bar', 'baz']); //=> []
R.dropLast(4, ['foo', 'bar', 'baz']); //=> []
R.dropLast(3, 'ramda');               //=> 'ra'

dropLastWhile List

(a → Boolean) → [a] → [a]
Parameters
  • function fn

    The function called per iteration.

  • Array list

    The collection to iterate over.

Returns Array

A new array.

Added in v0.16.0

Returns a new list containing all but last then elements of a given list, passing each value from the right to the supplied predicate function, skipping elements while the predicate function returns true. The predicate function is passed one argument: (value)*.

See also takeLastWhile, addIndex.
var lteThree = x => x <= 3;

R.dropLastWhile(lteThree, [1, 2, 3, 4, 3, 2, 1]); //=> [1, 2, 3, 4]

dropRepeats List

[a] → [a]
Parameters
  • Array list

    The array to consider.

Returns Array

list without repeating elements.

Added in v0.14.0

Returns a new list without any consecutively repeating elements. R.equals is used to determine equality.

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

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

See also transduce.
R.dropRepeats([1, 1, 1, 2, 3, 4, 4, 2, 2]); //=> [1, 2, 3, 4, 2]

dropRepeatsWith List

(a, a → Boolean) → [a] → [a]
Parameters
  • function pred

    A predicate used to test whether two items are equal.

  • Array list

    The array to consider.

Returns Array

list without repeating elements.

Added in v0.14.0

Returns a new list without any consecutively repeating elements. Equality is determined by applying the supplied predicate two consecutive elements. The first element in a series of equal element is the one being preserved.

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

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

See also transduce.
var lengthEq = (x, y) => Math.abs(x) === Math.abs(y);
var l = [1, -1, 1, 3, 4, -4, -4, -5, 5, 3, 3];
R.dropRepeatsWith(R.eqBy(Math.abs), l); //=> [1, 3, 4, -5, 3]

dropWhile List

(a → Boolean) → [a] → [a]
Parameters
  • function fn

    The function called per iteration.

  • Array list

    The collection to iterate over.

Returns Array

A new array.

Added in v0.9.0

Returns a new list containing the last n elements of a given list, passing each value to the supplied predicate function, skipping elements while the predicate function returns true. The predicate function is passed one argument: (value).

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

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

var lteTwo = x => x <= 2;

R.dropWhile(lteTwo, [1, 2, 3, 4, 3, 2, 1]); //=> [3, 4, 3, 2, 1]

either Logic

(*… → Boolean) → (*… → Boolean) → (*… → Boolean)
Parameters
  • function f

    a predicate

  • function g

    another predicate

Returns function

a function that applies its arguments to f and g and ||s their outputs together.

Added in v0.12.0

A function wrapping calls to the two functions in an || operation, returning the result of the first function if it is truth-y and the result of the second function otherwise. Note that this is short-circuited, meaning that the second function will not be invoked if the first returns a truth-y value.

See also or.
var gt10 = x => x > 10;
var even = x => x % 2 === 0;
var f = R.either(gt10, even);
f(101); //=> true
f(8); //=> true

empty Function

a → a
Parameters
  • * x
Returns *

Added in v0.3.0

Returns the empty value of its argument's type. Ramda defines the empty value of Array ([]), Object ({}), String (''), and Arguments. Other types are supported if they define <Type>.empty and/or <Type>.prototype.empty.

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

R.empty(Just(42));      //=> Nothing()
R.empty([1, 2, 3]);     //=> []
R.empty('unicorns');    //=> ''
R.empty({x: 1, y: 2});  //=> {}

eqBy Relation

(a → b) → a → a → Boolean
Parameters
  • function f
  • * x
  • * y
Returns Boolean

Added in v0.18.0

Takes a function and two values in its domain and returns true if the values map to the same value in the codomain; false otherwise.

R.eqBy(Math.abs, 5, -5); //=> true

eqProps Object

k → {k: v} → {k: v} → Boolean
Parameters
  • String prop

    The name of the property to compare

  • Object obj1
  • Object obj2
Returns Boolean

Added in v0.1.0

Reports whether two objects have the same value, in R.equals terms, for the specified property. Useful as a curried predicate.

var o1 = { a: 1, b: 2, c: 3, d: 4 };
var o2 = { a: 10, b: 20, c: 3, d: 40 };
R.eqProps('a', o1, o2); //=> false
R.eqProps('c', o1, o2); //=> true

equals Relation

a → b → Boolean
Parameters
  • * a
  • * b
Returns Boolean

Added in v0.15.0

Returns true if its arguments are equivalent, false otherwise. Handles cyclical data structures.

Dispatches symmetrically to the equals methods of both arguments, if present.

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

var a = {}; a.v = a;
var b = {}; b.v = b;
R.equals(a, b); //=> true

evolve Object

{k: (v → v)} → {k: v} → {k: v}
Parameters
  • Object transformations

    The object specifying transformation functions to apply to the object.

  • Object object

    The object to be transformed.

Returns Object

The transformed object.

Added in v0.9.0

Creates a new object by recursively evolving a shallow copy of object, according to the transformation functions. All non-primitive properties are copied by reference.

A transformation function will not be invoked if its corresponding key does not exist in the evolved object.

var tomato  = {firstName: '  Tomato ', data: {elapsed: 100, remaining: 1400}, id:123};
var transformations = {
  firstName: R.trim,
  lastName: R.trim, // Will not get invoked.
  data: {elapsed: R.add(1), remaining: R.add(-1)}
};
R.evolve(transformations, tomato); //=> {firstName: 'Tomato', data: {elapsed: 101, remaining: 1399}, id:123}

F Function

* → Boolean
Parameters
  • *
Returns Boolean

Added in v0.9.0

A function that always returns false. Any passed in parameters are ignored.

See also always, T.
R.F(); //=> false

filter List

Filterable f => (a → Boolean) → f a → f a
Parameters
  • function pred
  • Array filterable
Returns Array

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.

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.
var isEven = n => n % 2 === 0;

R.filter(isEven, [1, 2, 3, 4]); //=> [2, 4]

R.filter(isEven, {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, d: 4}

find List

(a → Boolean) → [a] → a | undefined
Parameters
  • function fn

    The predicate function used to determine if the element is the desired one.

  • Array list

    The 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.
var xs = [{a: 1}, {a: 2}, {a: 3}];
R.find(R.propEq('a', 2))(xs); //=> {a: 2}
R.find(R.propEq('a', 4))(xs); //=> undefined

findIndex List

(a → Boolean) → [a] → Number
Parameters
  • function fn

    The predicate function used to determine if the element is the desired one.

  • Array list

    The 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.

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

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

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

findLast List

(a → Boolean) → [a] → a | undefined
Parameters
  • function fn

    The predicate function used to determine if the element is the desired one.

  • Array list

    The 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.

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

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

See also transduce.
var xs = [{a: 1, b: 0}, {a:1, b: 1}];
R.findLast(R.propEq('a', 1))(xs); //=> {a: 1, b: 1}
R.findLast(R.propEq('a', 4))(xs); //=> undefined

findLastIndex List

(a → Boolean) → [a] → Number
Parameters
  • function fn

    The predicate function used to determine if the element is the desired one.

  • Array list

    The 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.

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

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

See also transduce.
var xs = [{a: 1, b: 0}, {a:1, b: 1}];
R.findLastIndex(R.propEq('a', 1))(xs); //=> 1
R.findLastIndex(R.propEq('a', 4))(xs); //=> -1

flatten List

[a] → [b]
Parameters
  • Array list

    The 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.
R.flatten([1, 2, [3, 4], 5, [6, [7, 8, [9, [10, 11], 12]]]]);
//=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

flip Function

(a → b → c → … → z) → (b → a → c → … → z)
Parameters
  • function fn

    The function to invoke with its first two parameters reversed.

Returns *

The result of invoking fn with its first two parameters' order reversed.

Added in v0.1.0

Returns a new function much like the supplied one, except that the first two arguments' order is reversed.

var mergeThree = (a, b, c) => [].concat(a, b, c);

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

R.flip(mergeThree)(1, 2, 3); //=> [2, 1, 3]

forEach List

(a → *) → [a] → [a]
Parameters
  • function fn

    The function to invoke. Receives one argument, value.

  • Array list

    The 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.
var printXPlusFive = x => console.log(x + 5);
R.forEach(printXPlusFive, [1, 2, 3]); //=> [1, 2, 3]
//-> 6
//-> 7
//-> 8

fromPairs List

[[k,v]] → {k: v}
Parameters
  • Array pairs

    An array of two-element arrays that will be the keys and values of the output object.

Returns Object

The object made by pairing up keys and values.

Added in v0.3.0

Creates a new object out of a list key-value pairs.

See also toPairs, pair.
R.fromPairs([['a', 1], ['b', 2],  ['c', 3]]); //=> {a: 1, b: 2, c: 3}

groupBy List

(a → String) → [a] → {String: [a]}
Parameters
  • function fn

    Function :: a -> String

  • Array list

    The array to group

Returns Object

An object with the output of fn for keys, mapped to arrays of elements that produced that key when passed to fn.

Added in v0.1.0

Splits a list into sub-lists stored in an object, based on the result of calling a String-returning function on each element, and grouping the results according to values returned.

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

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

See also transduce.
var byGrade = R.groupBy(function(student) {
  var score = student.score;
  return score < 65 ? 'F' :
         score < 70 ? 'D' :
         score < 80 ? 'C' :
         score < 90 ? 'B' : 'A';
});
var students = [{name: 'Abby', score: 84},
                {name: 'Eddy', score: 58},
                // ...
                {name: 'Jack', score: 69}];
byGrade(students);
// {
//   'A': [{name: 'Dianne', score: 99}],
//   'B': [{name: 'Abby', score: 84}]
//   // ...,
//   'F': [{name: 'Eddy', score: 58}]
// }

gt Relation

Ord a => a → a → Boolean
Parameters
  • * a
  • * b
Returns Boolean

Added in v0.1.0

Returns true if the first argument is greater than the second; false otherwise.

See also lt.
R.gt(2, 1); //=> true
R.gt(2, 2); //=> false
R.gt(2, 3); //=> false
R.gt('a', 'z'); //=> false
R.gt('z', 'a'); //=> true

gte Relation

Ord a => a → a → Boolean
Parameters
  • Number a
  • Number b
Returns Boolean

Added in v0.1.0

Returns true if the first argument is greater than or equal to the second; false otherwise.

See also lte.
R.gte(2, 1); //=> true
R.gte(2, 2); //=> true
R.gte(2, 3); //=> false
R.gte('a', 'z'); //=> false
R.gte('z', 'a'); //=> true

has Object

s → {s: x} → Boolean
Parameters
  • String prop

    The name of the property to check for.

  • Object obj

    The object to query.

Returns Boolean

Whether the property exists.

Added in v0.7.0

Returns whether or not an object has an own property with the specified name

var hasName = R.has('name');
hasName({name: 'alice'});   //=> true
hasName({name: 'bob'});     //=> true
hasName({});                //=> false

var point = {x: 0, y: 0};
var pointHas = R.has(R.__, point);
pointHas('x');  //=> true
pointHas('y');  //=> true
pointHas('z');  //=> false

hasIn Object

s → {s: x} → Boolean
Parameters
  • String prop

    The name of the property to check for.

  • Object obj

    The object to query.

Returns Boolean

Whether the property exists.

Added in v0.7.0

Returns whether or not an object or its prototype chain has a property with the specified name

function Rectangle(width, height) {
  this.width = width;
  this.height = height;
}
Rectangle.prototype.area = function() {
  return this.width * this.height;
};

var square = new Rectangle(2, 2);
R.hasIn('width', square);  //=> true
R.hasIn('area', square);  //=> true

identical Relation

a → a → Boolean
Parameters
  • * a
  • * b
Returns Boolean

Added in v0.15.0

Returns true if its arguments are identical, false otherwise. Values are identical if they reference the same memory. NaN is identical to NaN; 0 and -0 are not identical.

var o = {};
R.identical(o, o); //=> true
R.identical(1, 1); //=> true
R.identical(1, '1'); //=> false
R.identical([], []); //=> false
R.identical(0, -0); //=> false
R.identical(NaN, NaN); //=> true

identity Function

a → a
Parameters
  • * x

    The value to return.

Returns *

The input value, x.

Added in v0.1.0

A function that does nothing but return the parameter supplied to it. Good as a default or placeholder function.

R.identity(1); //=> 1

var obj = {};
R.identity(obj) === obj; //=> true

ifElse Logic

(*… → Boolean) → (*… → *) → (*… → *) → (*… → *)
Parameters
  • function condition

    A predicate function

  • function onTrue

    A function to invoke when the condition evaluates to a truthy value.

  • function onFalse

    A function to invoke when the condition evaluates to a falsy value.

Returns function

A new unary function that will process either the onTrue or the onFalse function depending upon the result of the condition predicate.

Added in v0.8.0

Creates a function that will process either the onTrue or the onFalse function depending upon the result of the condition predicate.

See also unless, when.
var incCount = R.ifElse(
  R.has('count'),
  R.over(R.lensProp('count'), R.inc),
  R.assoc('count', 1)
);
incCount({});           //=> { count: 1 }
incCount({ count: 1 }); //=> { count: 2 }

inc Math

Number → Number
Parameters
  • Number n
Returns Number

Added in v0.9.0

Increments its argument.

See also dec.
R.inc(42); //=> 43

indexBy List

(a → String) → [{k: v}] → {k: {k: v}}
Parameters
  • function fn

    Function :: a -> String

  • Array array

    The array of objects to index

Returns Object

An object indexing each array element by the given property.

Added in 0.19.0

Given a function that generates a key, turns a list of objects into an object indexing the objects by the given key. Note that if multiple objects generate the same value for the indexing key only the last value will be included in the generated object.

var list = [{id: 'xyz', title: 'A'}, {id: 'abc', title: 'B'}];
R.indexBy(R.prop('id'), list);
//=> {abc: {id: 'abc', title: 'B'}, xyz: {id: 'xyz', title: 'A'}}

indexOf List

a → [a] → Number
Parameters
  • * target

    The item to find.

  • Array xs

    The 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.
R.indexOf(3, [1,2,3,4]); //=> 2
R.indexOf(10, [1,2,3,4]); //=> -1

init List

[a] → [a]
String → String
Parameters
  • * list
Returns *

Added in v0.9.0

Returns all but the last element of the given list or string.

See also last, head, tail.
R.init([1, 2, 3]);  //=> [1, 2]
R.init([1, 2]);     //=> [1]
R.init([1]);        //=> []
R.init([]);         //=> []

R.init('abc');  //=> 'ab'
R.init('ab');   //=> 'a'
R.init('a');    //=> ''
R.init('');     //=> ''

insert List

Number → a → [a] → [a]
Parameters
  • Number index

    The position to insert the element

  • * elt

    The element to insert into the Array

  • Array list

    The 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 index 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.

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

insertAll List

Number → [a] → [a] → [a]
Parameters
  • Number index

    The position to insert the sub-list

  • Array elts

    The sub-list to insert into the Array

  • Array list

    The list to insert the sub-list into

Returns Array

A new Array with elts inserted starting at index.

Added in v0.9.0

Inserts the sub-list into the list, at index 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.

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

intersection Relation

[*] → [*] → [*]
Parameters
  • Array list1

    The first list.

  • Array list2

    The second list.

Returns Array

The list of elements found in both list1 and list2.

Added in v0.1.0

Combines two lists into a set (i.e. no duplicates) composed of those elements common to both lists.

See also intersectionWith.
R.intersection([1,2,3,4], [7,6,5,4,3]); //=> [4, 3]

intersectionWith Relation

(a → a → Boolean) → [*] → [*] → [*]
Parameters
  • function pred

    A predicate function that determines whether the two supplied elements are equal.

  • Array list1

    One list of items to compare

  • Array list2

    A second list of items to compare

Returns Array

A new list containing those elements common to both lists.

Added in v0.1.0

Combines two lists into a set (i.e. no duplicates) composed of those elements common to both lists. Duplication is determined according to the value returned by applying the supplied predicate to two list elements.

See also intersection.
var buffaloSpringfield = [
  {id: 824, name: 'Richie Furay'},
  {id: 956, name: 'Dewey Martin'},
  {id: 313, name: 'Bruce Palmer'},
  {id: 456, name: 'Stephen Stills'},
  {id: 177, name: 'Neil Young'}
];
var csny = [
  {id: 204, name: 'David Crosby'},
  {id: 456, name: 'Stephen Stills'},
  {id: 539, name: 'Graham Nash'},
  {id: 177, name: 'Neil Young'}
];

R.intersectionWith(R.eqBy(R.prop('id')), buffaloSpringfield, csny);
//=> [{id: 456, name: 'Stephen Stills'}, {id: 177, name: 'Neil Young'}]

intersperse List

a → [a] → [a]
Parameters
  • * separator

    The element to add to the list.

  • Array list

    The list to be interposed.

Returns Array

The new list.

Added in v0.14.0

Creates a new list with the separator interposed between elements.

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

R.intersperse('n', ['ba', 'a', 'a']); //=> ['ba', 'n', 'a', 'n', 'a']

into List

a → (b → b) → [c] → a
Parameters
  • * acc

    The initial accumulator value.

  • function xf

    The transducer function. Receives a transformer and returns a transformer.

  • Array list

    The list to iterate over.

Returns *

The final, accumulated value.

Added in v0.12.0

Transforms the items of the list with the transducer and appends the transformed items to the accumulator using an appropriate iterator function based on the accumulator type.

The accumulator can be an array, string, object or a transformer. Iterated items will be appended to arrays and concatenated to strings. Objects will be merged directly or 2-item arrays will be merged as key, value pairs.

The accumulator can also be a transformer object that provides a 2-arity reducing iterator function, step, 0-arity initial value function, init, and 1-arity result extraction function result. The step function is used as the iterator function in reduce. The result function is used to convert the final accumulator into the return type and in most cases is R.identity. The init function is used to provide the initial accumulator.

The iteration is performed with R.reduce after initializing the transducer.

var numbers = [1, 2, 3, 4];
var transducer = R.compose(R.map(R.add(1)), R.take(2));

R.into([], transducer, numbers); //=> [2, 3]

var intoArray = R.into([]);
intoArray(transducer, numbers); //=> [2, 3]

invert Object

{s: x} → {x: [ s, … ]}
Parameters
  • Object obj

    The object or array to invert

Returns Object

out A new object with keys in an array.

Added in v0.9.0

Same as R.invertObj, however this accounts for objects with duplicate values by putting the values into an array.

var raceResultsByFirstName = {
  first: 'alice',
  second: 'jake',
  third: 'alice',
};
R.invert(raceResultsByFirstName);
//=> { 'alice': ['first', 'third'], 'jake':['second'] }

invertObj Object

{s: x} → {x: s}
Parameters
  • Object obj

    The object or array to invert

Returns Object

out A new object

Added in v0.9.0

Returns a new object with the keys of the given object as values, and the values of the given object, which are coerced to strings, as keys. Note that the last key found is preferred when handling the same value.

var raceResults = {
  first: 'alice',
  second: 'jake'
};
R.invertObj(raceResults);
//=> { 'alice': 'first', 'jake':'second' }

// Alternatively:
var raceResults = ['alice', 'jake'];
R.invertObj(raceResults);
//=> { 'alice': '0', 'jake':'1' }

invoker Function

Number → String → (a → b → … → n → Object → *)
Parameters
  • Number arity

    Number of arguments the returned function should take before the target object.

  • String method

    Name of the method to call.

Returns function

A new curried function.

Added in v0.1.0

Turns a named method with a specified arity into a function that can be called directly supplied with arguments and a target object.

The returned function is curried and accepts arity + 1 parameters where the final parameter is the target object.

var sliceFrom = R.invoker(1, 'slice');
sliceFrom(6, 'abcdefghijklm'); //=> 'ghijklm'
var sliceFrom6 = R.invoker(2, 'slice')(6);
sliceFrom6(8, 'abcdefghijklm'); //=> 'gh'

is Type

(* → {*}) → a → Boolean
Parameters
  • Object ctor

    A constructor

  • * val

    The value to test

Returns Boolean

Added in v0.3.0

See if an object (val) is an instance of the supplied constructor. This function will check up the inheritance chain, if any.

R.is(Object, {}); //=> true
R.is(Number, 1); //=> true
R.is(Object, 1); //=> false
R.is(String, 's'); //=> true
R.is(String, new String('')); //=> true
R.is(Object, new String('')); //=> true
R.is(Object, 's'); //=> false
R.is(Number, {}); //=> false

isArrayLike Type

* → Boolean
Parameters
  • * x

    The object to test.

Returns Boolean

true if x has a numeric length property and extreme indices defined; false otherwise.

Added in v0.5.0

Tests whether or not an object is similar to an array.

R.isArrayLike([]); //=> true
R.isArrayLike(true); //=> false
R.isArrayLike({}); //=> false
R.isArrayLike({length: 10}); //=> false
R.isArrayLike({0: 'zero', 9: 'nine', length: 10}); //=> true

isEmpty Logic

a → Boolean
Parameters
  • * x
Returns Boolean

Added in v0.1.0

Returns true if the given value is its type's empty value; false otherwise.

See also empty.
R.isEmpty([1, 2, 3]);   //=> false
R.isEmpty([]);          //=> true
R.isEmpty('');          //=> true
R.isEmpty(null);        //=> false
R.isEmpty({});          //=> true
R.isEmpty({length: 0}); //=> false

isNil Type

* → Boolean
Parameters
  • * x

    The value to test.

Returns Boolean

true if x is undefined or null, otherwise false.

Added in v0.9.0

Checks if the input value is null or undefined.

R.isNil(null); //=> true
R.isNil(undefined); //=> true
R.isNil(0); //=> false
R.isNil([]); //=> false

join List

String → [a] → String
Parameters
  • Number separator

    The string used to separate the elements.

  • Array xs

    The 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.
var spacer = R.join(' ');
spacer(['a', 2, 3.4]);   //=> 'a 2 3.4'
R.join('|', [1, 2, 3]);    //=> '1|2|3'

juxt Function

[(a, b, …, m) → n] → ((a, b, …, m) → [n])
Parameters
  • Array fns

    An array of functions

Returns function

A function that returns a list of values after applying each of the original fns to its parameters.

Added in 0.19.0

juxt applies a list of functions to a list of values.

var range = R.juxt([Math.min, Math.max]);
range(3, 4, 9, -3); //=> [-3, 9]

keys Object

{k: v} → [k]
Parameters
  • Object obj

    The object to extract properties from

Returns Array

An array of the object's own properties.

Added in v0.1.0

Returns a list containing the names of all the enumerable own properties of the supplied object. Note that the order of the output array is not guaranteed to be consistent across different JS platforms.

R.keys({a: 1, b: 2, c: 3}); //=> ['a', 'b', 'c']

keysIn Object

{k: v} → [k]
Parameters
  • Object obj

    The object to extract properties from

Returns Array

An array of the object's own and prototype properties.

Added in v0.2.0

Returns a list containing the names of all the properties of the supplied object, including prototype properties. Note that the order of the output array is not guaranteed to be consistent across different JS platforms.

var F = function() { this.x = 'X'; };
F.prototype.y = 'Y';
var f = new F();
R.keysIn(f); //=> ['x', 'y']

last List

[a] → a | Undefined
String → String
Parameters
  • * list
Returns *

Added in v0.1.4

Returns the last element of the given list or string.

See also init, head, tail.
R.last(['fi', 'fo', 'fum']); //=> 'fum'
R.last([]); //=> undefined

R.last('abc'); //=> 'c'
R.last(''); //=> ''

lastIndexOf List

a → [a] → Number
Parameters
  • * target

    The item to find.

  • Array xs

    The 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.
R.lastIndexOf(3, [-1,3,3,0,1,2,3,4]); //=> 6
R.lastIndexOf(10, [1,2,3,4]); //=> -1

length List

[a] → Number
Parameters
  • Array list

    The array to inspect.

Returns Number

The length of the array.

Added in v0.3.0

Returns the number of elements in the array by returning list.length.

R.length([]); //=> 0
R.length([1, 2, 3]); //=> 3

lens Object

(s → a) → ((a, s) → s) → Lens s a
Lens s a = Functor f => (a → f a) → s → f s
Parameters
  • function getter
  • function setter
Returns Lens

Added in v0.8.0

Returns a lens for the given getter and setter functions. The getter "gets" the value of the focus; the setter "sets" the value of the focus. The setter should not mutate the data structure.

See also view, set, over, lensIndex, lensProp.
var xLens = R.lens(R.prop('x'), R.assoc('x'));

R.view(xLens, {x: 1, y: 2});            //=> 1
R.set(xLens, 4, {x: 1, y: 2});          //=> {x: 4, y: 2}
R.over(xLens, R.negate, {x: 1, y: 2});  //=> {x: -1, y: 2}

lensIndex Object

Number → Lens s a
Lens s a = Functor f => (a → f a) → s → f s
Parameters
  • Number n
Returns Lens

Added in v0.14.0

Returns a lens whose focus is the specified index.

See also view, set, over.
var headLens = R.lensIndex(0);

R.view(headLens, ['a', 'b', 'c']);            //=> 'a'
R.set(headLens, 'x', ['a', 'b', 'c']);        //=> ['x', 'b', 'c']
R.over(headLens, R.toUpper, ['a', 'b', 'c']); //=> ['A', 'b', 'c']

lensPath Object

[String] → Lens s a
Lens s a = Functor f => (a → f a) → s → f s
Parameters
  • Array path

    The path to use.

Returns Lens

Added in 0.19.0

Returns a lens whose focus is the specified path.

See also view, set, over.
var xyLens = R.lensPath(['x', 'y']);

R.view(xyLens, {x: {y: 2, z: 3}});            //=> 2
R.set(xyLens, 4, {x: {y: 2, z: 3}});          //=> {x: {y: 4, z: 3}}
R.over(xyLens, R.negate, {x: {y: 2, z: 3}});  //=> {x: {y: -2, z: 3}}

lensProp Object

String → Lens s a
Lens s a = Functor f => (a → f a) → s → f s
Parameters
  • String k
Returns Lens

Added in v0.14.0

Returns a lens whose focus is the specified property.

See also view, set, over.
var xLens = R.lensProp('x');

R.view(xLens, {x: 1, y: 2});            //=> 1
R.set(xLens, 4, {x: 1, y: 2});          //=> {x: 4, y: 2}
R.over(xLens, R.negate, {x: 1, y: 2});  //=> {x: -1, y: 2}

lift Function

(*… → *) → ([*]… → [*])
Parameters
  • function fn

    The function to lift into higher context

Returns function

The lifted function.

Added in v0.7.0

"lifts" a function of arity > 1 so that it may "map over" an Array or other object that satisfies the FantasyLand Apply spec.

See also liftN.
var madd3 = R.lift(R.curry((a, b, c) => a + b + c));

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

var madd5 = R.lift(R.curry((a, b, c, d, e) => a + b + c + d + e));

madd5([1,2], [3], [4, 5], [6], [7, 8]); //=> [21, 22, 22, 23, 22, 23, 23, 24]

liftN Function

Number → (*… → *) → ([*]… → [*])
Parameters
  • function fn

    The function to lift into higher context

Returns function

The lifted function.

Added in v0.7.0

"lifts" a function to be the specified arity, so that it may "map over" that many lists (or other objects that satisfies the FantasyLand Apply spec).

See also lift.
var madd3 = R.liftN(3, R.curryN(3, (...args) => R.sum(args)));
madd3([1,2,3], [1,2,3], [1]); //=> [3, 4, 5, 4, 5, 6, 5, 6, 7]

lt Relation

Ord a => a → a → Boolean
Parameters
  • * a
  • * b
Returns Boolean

Added in v0.1.0

Returns true if the first argument is less than the second; false otherwise.

See also gt.
R.lt(2, 1); //=> false
R.lt(2, 2); //=> false
R.lt(2, 3); //=> true
R.lt('a', 'z'); //=> true
R.lt('z', 'a'); //=> false

lte Relation

Ord a => a → a → Boolean
Parameters
  • Number a
  • Number b
Returns Boolean

Added in v0.1.0

Returns true if the first argument is less than or equal to the second; false otherwise.

See also gte.
R.lte(2, 1); //=> false
R.lte(2, 2); //=> true
R.lte(2, 3); //=> true
R.lte('a', 'z'); //=> true
R.lte('z', 'a'); //=> false

map List

Functor f => (a → b) → f a → f b
Parameters
  • function fn

    The function to be called on every element of the input list.

  • Array list

    The 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.
var double = x => x * 2;

R.map(double, [1, 2, 3]); //=> [2, 4, 6]

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

mapAccum List

(acc → x → (acc, y)) → acc → [x] → (acc, [y])
Parameters
  • function fn

    The function to be called on every element of the input list.

  • * acc

    The accumulator value.

  • Array list

    The list to iterate over.

Returns *

The final, accumulated value.

Added in v0.10.0

The mapAccum function behaves like a combination of map and reduce; it applies a function to each element of a list, passing an accumulating parameter from left to right, and returning a final value of this accumulator together with the new list.

The iterator function receives two arguments, acc and value, and should return a tuple [acc, value].

See also addIndex.
var digits = ['1', '2', '3', '4'];
var appender = (a, b) => [a + b, a + b];

R.mapAccum(appender, 0, digits); //=> ['01234', ['01', '012', '0123', '01234']]

mapAccumRight List

(acc → x → (acc, y)) → acc → [x] → (acc, [y])
Parameters
  • function fn

    The function to be called on every element of the input list.

  • * acc

    The accumulator value.

  • Array list

    The list to iterate over.

Returns *

The final, accumulated value.

Added in v0.10.0

The mapAccumRight function behaves like a combination of map and reduce; it applies a function to each element of a list, passing an accumulating parameter from right to left, and returning a final value of this accumulator together with the new list.

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

The iterator function receives two arguments, acc and value, and should return a tuple [acc, value].

See also addIndex.
var digits = ['1', '2', '3', '4'];
var append = (a, b) => [a + b, a + b];

R.mapAccumRight(append, 0, digits); //=> ['04321', ['04321', '0432', '043', '04']]

mapObjIndexed Object

((*, String, Object) → *) → Object → Object
Parameters
  • function fn
  • Object obj
Returns Object

Added in v0.9.0

An Object-specific version of map. The function is applied to three arguments: (value, key, obj). If only the value is significant, use map instead.

See also map.
var values = { x: 1, y: 2, z: 3 };
var prependKeyAndDouble = (num, key, obj) => key + (num * 2);

R.mapObjIndexed(prependKeyAndDouble, values); //=> { x: 'x2', y: 'y4', z: 'z6' }

match String

RegExp → String → [String | Undefined]
Parameters
  • RegExp rx

    A regular expression.

  • String str

    The string to match against

Returns Array

The list of matches or empty array.

Added in v0.1.0

Tests a regular expression against a String. Note that this function will return an empty array when there are no matches. This differs from String.prototype.match which returns null when there are no matches.

See also test.
R.match(/([a-z]a)/g, 'bananas'); //=> ['ba', 'na', 'na']
R.match(/a/, 'b'); //=> []
R.match(/a/, null); //=> TypeError: null does not have a method named "match"

mathMod Math

Number → Number → Number
Parameters
  • Number m

    The dividend.

  • Number p

    the modulus.

Returns Number

The result of b mod a.

Added in v0.3.0

mathMod behaves like the modulo operator should mathematically, unlike the % operator (and by extension, R.modulo). So while "-17 % 5" is -2, mathMod(-17, 5) is 3. mathMod requires Integer arguments, and returns NaN when the modulus is zero or negative.

R.mathMod(-17, 5);  //=> 3
R.mathMod(17, 5);   //=> 2
R.mathMod(17, -5);  //=> NaN
R.mathMod(17, 0);   //=> NaN
R.mathMod(17.2, 5); //=> NaN
R.mathMod(17, 5.3); //=> NaN

var clock = R.mathMod(R.__, 12);
clock(15); //=> 3
clock(24); //=> 0

var seventeenMod = R.mathMod(17);
seventeenMod(3);  //=> 2
seventeenMod(4);  //=> 1
seventeenMod(10); //=> 7

max Relation

Ord a => a → a → a
Parameters
  • * a
  • * b
Returns *

Added in v0.1.0

Returns the larger of its two arguments.

See also maxBy, min.
R.max(789, 123); //=> 789
R.max('a', 'b'); //=> 'b'

maxBy Relation

Ord b => (a → b) → a → a → a
Parameters
  • function f
  • * a
  • * b
Returns *

Added in v0.8.0

Takes a function and two values, and returns whichever value produces the larger result when passed to the provided function.

See also max, minBy.
//  square :: Number -> Number
var square = n => n * n;

R.maxBy(square, -3, 2); //=> -3

R.reduce(R.maxBy(square), 0, [3, -5, 4, 1, -2]); //=> -5
R.reduce(R.maxBy(square), 0, []); //=> 0

mean Math

[Number] → Number
Parameters
  • Array list
Returns Number

Added in v0.14.0

Returns the mean of the given list of numbers.

R.mean([2, 7, 9]); //=> 6
R.mean([]); //=> NaN

median Math

[Number] → Number
Parameters
  • Array list
Returns Number

Added in v0.14.0

Returns the median of the given list of numbers.

R.median([2, 9, 7]); //=> 7
R.median([7, 2, 10, 9]); //=> 8
R.median([]); //=> NaN

memoize Function

(*… → a) → (*… → a)
Parameters
  • function fn

    The function to memoize.

Returns function

Memoized version of fn.

Added in v0.1.0

Creates a new function that, when invoked, caches the result of calling fn for a given argument set and returns the result. Subsequent calls to the memoized fn with the same argument set will not result in an additional call to fn; instead, the cached result for that set of arguments will be returned.

var count = 0;
var factorial = R.memoize(n => {
  count += 1;
  return R.product(R.range(1, n + 1));
});
factorial(5); //=> 120
factorial(5); //=> 120
factorial(5); //=> 120
count; //=> 1

merge Object

{k: v} → {k: v} → {k: v}
Parameters
  • Object l
  • Object r
Returns Object

Added in v0.1.0

Create a new object with the own properties of the first object merged with the own properties of the second object. If a key exists in both objects, the value from the second object will be used.

See also mergeWith, mergeWithKey.
R.merge({ 'name': 'fred', 'age': 10 }, { 'age': 40 });
//=> { 'name': 'fred', 'age': 40 }

var resetToDefault = R.merge(R.__, {x: 0});
resetToDefault({x: 5, y: 2}); //=> {x: 0, y: 2}

mergeAll List

[{k: v}] → {k: v}
Parameters
  • Array list

    An array of objects

Returns Object

A merged object.

Added in v0.10.0

Merges a list of objects together into one object.

See also reduce.
R.mergeAll([{foo:1},{bar:2},{baz:3}]); //=> {foo:1,bar:2,baz:3}
R.mergeAll([{foo:1},{foo:2},{bar:2}]); //=> {foo:2,bar:2}

mergeWith Object

(a → a → a) → {a} → {a} → {a}
Parameters
  • function fn
  • Object l
  • Object r
Returns Object

Added in 0.19.0

Creates a new object with the own properties of the two provided objects. If a key exists in both objects, the provided function is applied to the values associated with the key in each object, with the result being used as the value associated with the key in the returned object. The key will be excluded from the returned object if the resulting value is undefined.

See also merge, mergeWithKey.
R.mergeWith(R.concat,
            { a: true, values: [10, 20] },
            { b: true, values: [15, 35] });
//=> { a: true, b: true, values: [10, 20, 15, 35] }

mergeWithKey Object

(String → a → a → a) → {a} → {a} → {a}
Parameters
  • function fn
  • Object l
  • Object r
Returns Object

Added in 0.19.0

Creates a new object with the own properties of the two provided objects. If a key exists in both objects, the provided function is applied to the key and the values associated with the key in each object, with the result being used as the value associated with the key in the returned object. The key will be excluded from the returned object if the resulting value is undefined.

See also merge, mergeWith.
let concatValues = (k, l, r) => k == 'values' ? R.concat(l, r) : r
R.mergeWithKey(concatValues,
               { a: true, thing: 'foo', values: [10, 20] },
               { b: true, thing: 'bar', values: [15, 35] });
//=> { a: true, b: true, thing: 'bar', values: [10, 20, 15, 35] }

min Relation

Ord a => a → a → a
Parameters
  • * a
  • * b
Returns *

Added in v0.1.0

Returns the smaller of its two arguments.

See also minBy, max.
R.min(789, 123); //=> 123
R.min('a', 'b'); //=> 'a'

minBy Relation

Ord b => (a → b) → a → a → a
Parameters
  • function f
  • * a
  • * b
Returns *

Added in v0.8.0

Takes a function and two values, and returns whichever value produces the smaller result when passed to the provided function.

See also min, maxBy.
//  square :: Number -> Number
var square = n => n * n;

R.minBy(square, -3, 2); //=> 2

R.reduce(R.minBy(square), Infinity, [3, -5, 4, 1, -2]); //=> 1
R.reduce(R.minBy(square), Infinity, []); //=> Infinity

modulo Math

Number → Number → Number
Parameters
  • Number a

    The value to the divide.

  • Number b

    The pseudo-modulus

Returns Number

The result of b % a.

Added in v0.1.1

Divides the second parameter by the first and returns the remainder. Note that this function preserves the JavaScript-style behavior for modulo. For mathematical modulo see mathMod.

See also mathMod.
R.modulo(17, 3); //=> 2
// JS behavior:
R.modulo(-17, 3); //=> -2
R.modulo(17, -3); //=> 2

var isOdd = R.modulo(R.__, 2);
isOdd(42); //=> 0
isOdd(21); //=> 1

multiply Math

Number → Number → Number
Parameters
  • Number a

    The first value.

  • Number b

    The second value.

Returns Number

The result of a * b.

Added in v0.1.0

Multiplies two numbers. Equivalent to a * b but curried.

See also divide.
var double = R.multiply(2);
var triple = R.multiply(3);
double(3);       //=>  6
triple(4);       //=> 12
R.multiply(2, 5);  //=> 10

nAry Function

Number → (* → a) → (* → a)
Parameters
  • Number n

    The desired arity of the new function.

  • function fn

    The function to wrap.

Returns function

A new function wrapping fn. The new function is guaranteed to be of arity n.

Added in v0.1.0

Wraps a function of any arity (including nullary) in a function that accepts exactly n parameters. Any extraneous parameters will not be passed to the supplied function.

var takesTwoArgs = (a, b) => [a, b];

takesTwoArgs.length; //=> 2
takesTwoArgs(1, 2); //=> [1, 2]

var takesOneArg = R.nAry(1, takesTwoArgs);
takesOneArg.length; //=> 1
// Only `n` arguments are passed to the wrapped function
takesOneArg(1, 2); //=> [1, undefined]

negate Math

Number → Number
Parameters
  • Number n
Returns Number

Added in v0.9.0

Negates its argument.

R.negate(42); //=> -42

none List

(a → Boolean) → [a] → Boolean
Parameters
  • function fn

    The predicate function.

  • Array list

    The array to consider.

Returns Boolean

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

Added in v0.12.0

Returns true if no elements of the list match the predicate, false otherwise.

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

See also all, any.
var isEven = n => n % 2 === 0;

R.none(isEven, [1, 3, 5, 7, 9, 11]); //=> true
R.none(isEven, [1, 3, 5, 7, 8, 11]); //=> false

not Logic

* → Boolean
Parameters
  • * a

    any value

Returns Boolean

the logical inverse of passed argument.

Added in v0.1.0

A function that returns the ! of its argument. It will return true when passed false-y value, and false when passed a truth-y one.

See also complement.
R.not(true); //=> false
R.not(false); //=> true
R.not(0); => true
R.not(1); => false

nth List

Number → [a] → a | Undefined
Number → String → String
Parameters
  • Number offset
  • * list
Returns *

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.

var list = ['foo', 'bar', 'baz', 'quux'];
R.nth(1, list); //=> 'bar'
R.nth(-1, list); //=> 'quux'
R.nth(-99, list); //=> undefined

R.nth('abc', 2); //=> 'c'
R.nth('abc', 3); //=> ''

nthArg Function

Number → *… → *
Parameters
  • Number n
Returns function

Added in v0.9.0

Returns a function which returns its nth argument.

R.nthArg(1)('a', 'b', 'c'); //=> 'b'
R.nthArg(-1)('a', 'b', 'c'); //=> 'c'

objOf Object

String → a → {String:a}
Parameters
  • String key
  • * val
Returns Object

Added in v0.18.0

Creates an object containing a single key:value pair.

See also pair.
var matchPhrases = R.compose(
  R.objOf('must'),
  R.map(R.objOf('match_phrase'))
);
matchPhrases(['foo', 'bar', 'baz']); //=> {must: [{match_phrase: 'foo'}, {match_phrase: 'bar'}, {match_phrase: 'baz'}]}

of Function

a → [a]
Parameters
  • * x

    any value

Returns Array

An array wrapping x.

Added in v0.3.0

Returns a singleton array containing the value provided.

Note this of is different from the ES6 of; See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of

R.of(null); //=> [null]
R.of([42]); //=> [[42]]

omit Object

[String] → {String: *} → {String: *}
Parameters
  • Array names

    an array of String property names to omit from the new object

  • Object obj

    The object to copy from

Returns Object

A new object with properties from names not on it.

Added in v0.1.0

Returns a partial copy of an object omitting the keys specified.

See also pick.
R.omit(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, c: 3}

once Function

(a… → b) → (a… → b)
Parameters
  • function fn

    The function to wrap in a call-only-once wrapper.

Returns function

The wrapped function.

Added in v0.1.0

Accepts a function fn and returns a function that guards invocation of fn such that fn can only ever be called once, no matter how many times the returned function is invoked. The first value calculated is returned in subsequent invocations.

var addOneOnce = R.once(x => x + 1);
addOneOnce(10); //=> 11
addOneOnce(addOneOnce(50)); //=> 11

or Logic

* → * → *
Parameters
  • Boolean a

    A boolean value

  • Boolean b

    A boolean value

Returns Boolean

true if one or both arguments are true, false otherwise

Added in v0.1.0

Returns true if one or both of its arguments are true. Returns false if both arguments are false.

See also either.
R.or(true, true); //=> true
R.or(true, false); //=> true
R.or(false, true); //=> true
R.or(false, false); //=> false

over Object

Lens s a → (a → a) → s → s
Lens s a = Functor f => (a → f a) → s → f s
Parameters
  • Lens lens
  • * v
  • * x
Returns *

Added in v0.16.0

Returns the result of "setting" the portion of the given data structure focused by the given lens to the result of applying the given function to the focused value.

See also prop, lensIndex, lensProp.
var headLens = R.lensIndex(0);

R.over(headLens, R.toUpper, ['foo', 'bar', 'baz']); //=> ['FOO', 'bar', 'baz']

pair List

a → b → (a,b)
Parameters
  • * fst
  • * snd
Returns Array

Added in v0.18.0

Takes two arguments, fst and snd, and returns [fst, snd].

See also createMapEntry, of.
R.pair('foo', 'bar'); //=> ['foo', 'bar']

partial Function

((a, b, c, …, n) → x) → [a, b, c, …] → ((d, e, f, …, n) → x)
Parameters
  • function f
  • Array args
Returns function

Added in v0.10.0

Takes a function f and a list of arguments, and returns a function g. When applied, g returns the result of applying f to the arguments provided initially followed by the arguments provided to g.

See also partialRight.
var multiply = (a, b) => a * b;
var double = R.partial(multiply, [2]);
double(2); //=> 4

var greet = (salutation, title, firstName, lastName) =>
  salutation + ', ' + title + ' ' + firstName + ' ' + lastName + '!';

var sayHello = R.partial(greet, ['Hello']);
var sayHelloToMs = R.partial(sayHello, ['Ms.']);
sayHelloToMs('Jane', 'Jones'); //=> 'Hello, Ms. Jane Jones!'

partialRight Function

((a, b, c, …, n) → x) → [d, e, f, …, n] → ((a, b, c, …) → x)
Parameters
  • function f
  • Array args
Returns function

Added in v0.10.0

Takes a function f and a list of arguments, and returns a function g. When applied, g returns the result of applying f to the arguments provided to g followed by the arguments provided initially.

See also partial.
var greet = (salutation, title, firstName, lastName) =>
  salutation + ', ' + title + ' ' + firstName + ' ' + lastName + '!';

var greetMsJaneJones = R.partialRight(greet, ['Ms.', 'Jane', 'Jones']);

greetMsJaneJones('Hello'); //=> 'Hello, Ms. Jane Jones!'

partition List

(a → Boolean) → [a] → [[a],[a]]
Parameters
  • function pred

    A predicate to determine which array the element belongs to.

  • Array list

    The array to partition.

Returns Array

A nested array, containing first an array of elements that satisfied the predicate, and second an array of elements that did not satisfy.

Added in v0.1.4

Takes a predicate and a list and returns the pair of lists of elements which do and do not satisfy the predicate, respectively.

See also filter, reject.
R.partition(R.contains('s'), ['sss', 'ttt', 'foo', 'bars']);
//=> [ [ 'sss', 'bars' ],  [ 'ttt', 'foo' ] ]

path Object

[String] → {k: v} → v | Undefined
Parameters
  • Array path

    The path to use.

  • Object obj

    The object to retrieve the nested property from.

Returns *

The data at path.

Added in v0.2.0

Retrieve the value at a given path.

R.path(['a', 'b'], {a: {b: 2}}); //=> 2
R.path(['a', 'b'], {c: {b: 2}}); //=> undefined

pathEq Relation

[String] → * → {String: *} → Boolean
Parameters
  • Array path

    The path of the nested property to use

  • * val

    The value to compare the nested property with

  • Object obj

    The object to check the nested property in

Returns Boolean

true if the value equals the nested object property, false otherwise.

Added in v0.7.0

Determines whether a nested path on an object has a specific value, in R.equals terms. Most likely used to filter a list.

var user1 = { address: { zipCode: 90210 } };
var user2 = { address: { zipCode: 55555 } };
var user3 = { name: 'Bob' };
var users = [ user1, user2, user3 ];
var isFamous = R.pathEq(['address', 'zipCode'], 90210);
R.filter(isFamous, users); //=> [ user1 ]

pathOr Object

a → [String] → Object → a
Parameters
  • * d

    The default value.

  • Array p

    The path to use.

  • Object obj

    The object to retrieve the nested property from.

Returns *

The data at path of the supplied object or the default value.

Added in v0.18.0

If the given, non-null object has a value at the given path, returns the value at that path. Otherwise returns the provided default value.

R.pathOr('N/A', ['a', 'b'], {a: {b: 2}}); //=> 2
R.pathOr('N/A', ['a', 'b'], {c: {b: 2}}); //=> "N/A"

pathSatisfies Logic

(a → Boolean) → [String] → Object → Boolean
Parameters
  • function pred
  • Array propPath
  • * obj
Returns Boolean

Added in 0.19.0

Returns true if the specified object property at given path satisfies the given predicate; false otherwise.

See also propSatisfies, path.
R.pathSatisfies(y => y > 0, ['x', 'y'], {x: {y: 2}}); //=> true

pick Object

[k] → {k: v} → {k: v}
Parameters
  • Array names

    an array of String property names to copy onto a new object

  • Object obj

    The object to copy from

Returns Object

A new object with only properties from names on it.

Added in v0.1.0

Returns a partial copy of an object containing only the keys specified. If the key does not exist, the property is ignored.

See also omit, props.
R.pick(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, d: 4}
R.pick(['a', 'e', 'f'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1}

pickAll Object

[k] → {k: v} → {k: v}
Parameters
  • Array names

    an array of String property names to copy onto a new object

  • Object obj

    The object to copy from

Returns Object

A new object with only properties from names on it.

Added in v0.1.0

Similar to pick except that this one includes a key: undefined pair for properties that don't exist.

See also pick.
R.pickAll(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, d: 4}
R.pickAll(['a', 'e', 'f'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, e: undefined, f: undefined}

pickBy Object

(v, k → Boolean) → {k: v} → {k: v}
Parameters
  • function pred

    A predicate to determine whether or not a key should be included on the output object.

  • Object obj

    The object to copy from

Returns Object

A new object with only properties that satisfy pred on it.

Added in v0.8.0

Returns a partial copy of an object containing only the keys that satisfy the supplied predicate.

See also pick, filter.
var isUpperCase = (val, key) => key.toUpperCase() === key;
R.pickBy(isUpperCase, {a: 1, b: 2, A: 3, B: 4}); //=> {A: 3, B: 4}

pipe Function

(((a, b, …, n) → o), (o → p), …, (x → y), (y → z)) → ((a, b, …, n) → z)
Parameters
  • function functions
Returns function

Added in v0.1.0

Performs left-to-right function composition. The leftmost function may have any arity; the remaining functions must be unary.

In some libraries this function is named sequence.

See also compose.
var f = R.pipe(Math.pow, R.negate, R.inc);

f(3, 4); // -(3^4) + 1

pipeK Function

Chain m => ((a → m b), (b → m c), …, (y → m z)) → (m a → m z)
Parameters
  • function
Returns function

Added in v0.16.0

Returns the left-to-right Kleisli composition of the provided functions, each of which must return a value of a type supported by chain.

R.pipeK(f, g, h) is equivalent to R.pipe(R.chain(f), R.chain(g), R.chain(h)).

See also composeK.
//  parseJson :: String -> Maybe *
//  get :: String -> Object -> Maybe *

//  getStateCode :: Maybe String -> Maybe String
var getStateCode = R.pipeK(
  parseJson,
  get('user'),
  get('address'),
  get('state'),
  R.compose(Maybe.of, R.toUpper)
);

getStateCode(Maybe.of('{"user":{"address":{"state":"ny"}}}'));
//=> Just('NY')
getStateCode(Maybe.of('[Invalid JSON]'));
//=> Nothing()

pipeP Function

((a → Promise b), (b → Promise c), …, (y → Promise z)) → (a → Promise z)
Parameters
  • function functions
Returns function

Added in v0.10.0

Performs left-to-right composition of one or more Promise-returning functions. The leftmost function may have any arity; the remaining functions must be unary.

See also composeP.
//  followersForUser :: String -> Promise [User]
var followersForUser = R.pipeP(db.getUserById, db.getFollowers);

pluck List

k → [{k: v}] → [v]
Parameters
  • Number key

    The key name to pluck off of each object.

  • Array list

    The array 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.

See also props.
R.pluck('a')([{a: 1}, {a: 2}]); //=> [1, 2]
R.pluck(0)([[1, 2], [3, 4]]);   //=> [1, 3]

prepend List

a → [a] → [a]
Parameters
  • * el

    The item to add to the head of the output list.

  • Array list

    The 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.
R.prepend('fee', ['fi', 'fo', 'fum']); //=> ['fee', 'fi', 'fo', 'fum']

product Math

[Number] → Number
Parameters
  • Array list

    An array of numbers

Returns Number

The product of all the numbers in the list.

Added in v0.1.0

Multiplies together all the elements of a list.

See also reduce.
R.product([2,4,6,8,100,1]); //=> 38400

project Object

[k] → [{k: v}] → [{k: v}]
Parameters
  • Array props

    The property names to project

  • Array objs

    The objects to query

Returns Array

An array of objects with just the props properties.

Added in v0.1.0

Reasonable analog to SQL select statement.

var abby = {name: 'Abby', age: 7, hair: 'blond', grade: 2};
var fred = {name: 'Fred', age: 12, hair: 'brown', grade: 7};
var kids = [abby, fred];
R.project(['name', 'grade'], kids); //=> [{name: 'Abby', grade: 2}, {name: 'Fred', grade: 7}]

prop Object

s → {s: a} → a | Undefined
Parameters
  • String p

    The property name

  • Object obj

    The object to query

Returns *

The value at obj.p.

Added in v0.1.0

Returns a function that when supplied an object returns the indicated property of that object, if it exists.

R.prop('x', {x: 100}); //=> 100
R.prop('x', {}); //=> undefined

propEq Relation

String → a → Object → Boolean
Parameters
  • String name
  • * val
  • * obj
Returns Boolean

Added in v0.1.0

Returns true if the specified object property is equal, in R.equals terms, to the given value; false otherwise.

See also equals, propSatisfies.
var abby = {name: 'Abby', age: 7, hair: 'blond'};
var fred = {name: 'Fred', age: 12, hair: 'brown'};
var rusty = {name: 'Rusty', age: 10, hair: 'brown'};
var alois = {name: 'Alois', age: 15, disposition: 'surly'};
var kids = [abby, fred, rusty, alois];
var hasBrownHair = R.propEq('hair', 'brown');
R.filter(hasBrownHair, kids); //=> [fred, rusty]

propIs Type

Type → String → Object → Boolean
Parameters
  • function type
  • String name
  • * obj
Returns Boolean

Added in v0.16.0

Returns true if the specified object property is of the given type; false otherwise.

See also is, propSatisfies.
R.propIs(Number, 'x', {x: 1, y: 2});  //=> true
R.propIs(Number, 'x', {x: 'foo'});    //=> false
R.propIs(Number, 'x', {});            //=> false

propOr Object

a → String → Object → a
Parameters
  • * val

    The default value.

  • String p

    The name of the property to return.

  • Object obj

    The object to query.

Returns *

The value of given property of the supplied object or the default value.

Added in v0.6.0

If the given, non-null object has an own property with the specified name, returns the value of that property. Otherwise returns the provided default value.

var alice = {
  name: 'ALICE',
  age: 101
};
var favorite = R.prop('favoriteLibrary');
var favoriteWithDefault = R.propOr('Ramda', 'favoriteLibrary');

favorite(alice);  //=> undefined
favoriteWithDefault(alice);  //=> 'Ramda'

props Object

[k] → {k: v} → [v]
Parameters
  • Array ps

    The property names to fetch

  • Object obj

    The object to query

Returns Array

The corresponding values or partially applied function.

Added in v0.1.0

Acts as multiple prop: array of keys in, array of values out. Preserves order.

R.props(['x', 'y'], {x: 1, y: 2}); //=> [1, 2]
R.props(['c', 'a', 'b'], {b: 2, a: 1}); //=> [undefined, 1, 2]

var fullName = R.compose(R.join(' '), R.props(['first', 'last']));
fullName({last: 'Bullet-Tooth', age: 33, first: 'Tony'}); //=> 'Tony Bullet-Tooth'

propSatisfies Logic

(a → Boolean) → String → {String: a} → Boolean
Parameters
  • function pred
  • String name
  • * obj
Returns Boolean

Added in v0.16.0

Returns true if the specified object property satisfies the given predicate; false otherwise.

See also propEq, propIs.
R.propSatisfies(x => x > 0, 'x', {x: 1, y: 2}); //=> true

range List

Number → Number → [Number]
Parameters
  • Number from

    The first number in the list.

  • Number to

    One more than the last number in the list.

Returns Array

The list of numbers in tthe set [a, b).

Added in v0.1.0

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

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

reduce List

((a, b) → a) → a → [b] → a
Parameters
  • function fn

    The iterator function. Receives two values, the accumulator and the current element from the array.

  • * acc

    The accumulator value.

  • Array list

    The 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.

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

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

See also reduced, addIndex.
var numbers = [1, 2, 3];
var add = (a, b) => a + b;

R.reduce(add, 10, numbers); //=> 16

reduced List

a → *
Parameters
  • * x

    The final value of the reduce.

Returns *

The wrapped value.

Added in v0.15.0

Returns a value wrapped to indicate that it is the final value of the reduce and transduce functions. The returned value should be considered a black box: the internal structure is not guaranteed to be stable.

Note: this optimization is unavailable to functions not explicitly listed above. For instance, it is not currently supported by reduceRight.

See also reduce, transduce.
R.reduce(
  R.pipe(R.add, R.when(R.gte(R.__, 10), R.reduced)),
  0,
  [1, 2, 3, 4, 5]) // 10

reduceRight List

(a,b → a) → a → [b] → a
Parameters
  • function fn

    The iterator function. Receives two values, the accumulator and the current element from the array.

  • * acc

    The accumulator value.

  • Array list

    The 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: (acc, value)

Note: R.reduceRight 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/reduceRight#Description

See also addIndex.
var pairs = [ ['a', 1], ['b', 2], ['c', 3] ];
var flattenPairs = (acc, pair) => acc.concat(pair);

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

reject List

Filterable f => (a → Boolean) → f a → f a
Parameters
  • function pred
  • Array filterable
Returns Array

Added in v0.1.0

The complement of filter.

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

See also filter, transduce, addIndex.
var isOdd = (n) => n % 2 === 1;

R.reject(isOdd, [1, 2, 3, 4]); //=> [2, 4]

R.reject(isOdd, {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, d: 4}

remove List

Number → Number → [a] → [a]
Parameters
  • Number start

    The position to start removing elements

  • Number count

    The number of elements to remove

  • Array list

    The 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.

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

repeat List

a → n → [a]
Parameters
  • * value

    The value to repeat.

  • Number n

    The 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.

R.repeat('hi', 5); //=> ['hi', 'hi', 'hi', 'hi', 'hi']

var obj = {};
var repeatedObjs = R.repeat(obj, 5); //=> [{}, {}, {}, {}, {}]
repeatedObjs[0] === repeatedObjs[1]; //=> true

replace String

RegExp|String → String → String → String
Parameters
  • RegExp pattern

    A regular expression or a substring to match.

  • String replacement

    The string to replace the matches with.

  • String str

    The String to do the search and replacement in.

Returns String

The result.

Added in v0.7.0

Replace a substring or regex match in a string with a replacement.

R.replace('foo', 'bar', 'foo foo foo'); //=> 'bar foo foo'
R.replace(/foo/, 'bar', 'foo foo foo'); //=> 'bar foo foo'

// Use the "g" (global) flag to replace all occurrences:
R.replace(/foo/g, 'bar', 'foo foo foo'); //=> 'bar bar bar'

reverse List

[a] → [a]
String → String
Parameters
  • Array list
Returns Array

Added in v0.1.0

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

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

R.reverse('abc');      //=> 'cba'
R.reverse('ab');       //=> 'ba'
R.reverse('a');        //=> 'a'
R.reverse('');         //=> ''

scan List

(a,b → a) → a → [b] → [a]
Parameters
  • function fn

    The iterator function. Receives two values, the accumulator and the current element from the array

  • * acc

    The accumulator value.

  • Array list

    The list to iterate over.

Returns Array

A list of all intermediately reduced values.

Added in v0.10.0

Scan is similar to reduce, but returns a list of successively reduced values from the left

var numbers = [1, 2, 3, 4];
var factorials = R.scan(R.multiply, 1, numbers); //=> [1, 1, 2, 6, 24]

sequence List

(Applicative f, Traversable t) => (a → f a) → t (f a) → f (t a)
Parameters
  • function of
  • * traversable
Returns *

Added in 0.19.0

Transforms a Traversable of Applicative into an Applicative of Traversable.

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

See also traverse.
R.sequence(Maybe.of, [Just(1), Just(2), Just(3)]);   //=> Just([1, 2, 3])
R.sequence(Maybe.of, [Just(1), Just(2), Nothing()]); //=> Nothing()

R.sequence(R.of, Just([1, 2, 3])); //=> [Just(1), Just(2), Just(3)]
R.sequence(R.of, Nothing());       //=> [Nothing()]

set Object

Lens s a → a → s → s
Lens s a = Functor f => (a → f a) → s → f s
Parameters
  • Lens lens
  • * v
  • * x
Returns *

Added in v0.16.0

Returns the result of "setting" the portion of the given data structure focused by the given lens to the given value.

See also prop, lensIndex, lensProp.
var xLens = R.lensProp('x');

R.set(xLens, 4, {x: 1, y: 2});  //=> {x: 4, y: 2}
R.set(xLens, 8, {x: 1, y: 2});  //=> {x: 8, y: 2}

slice List

Number → Number → [a] → [a]
Number → Number → String → String
Parameters
  • Number fromIndex

    The start index (inclusive).

  • Number toIndex

    The 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.

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

sort List

(a,a → Number) → [a] → [a]
Parameters
  • function comparator

    A sorting function :: a -> b -> Int

  • Array list

    The 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.

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

sortBy Relation

Ord b => (a → b) → [a] → [a]
Parameters
  • function fn
  • Array list

    The list to sort.

Returns Array

A new list sorted by the keys generated by fn.

Added in v0.1.0

Sorts the list according to the supplied function.

var sortByFirstItem = R.sortBy(R.prop(0));
var sortByNameCaseInsensitive = R.sortBy(R.compose(R.toLower, R.prop('name')));
var pairs = [[-1, 1], [-2, 2], [-3, 3]];
sortByFirstItem(pairs); //=> [[-3, 3], [-2, 2], [-1, 1]]
var alice = {
  name: 'ALICE',
  age: 101
};
var bob = {
  name: 'Bob',
  age: -10
};
var clara = {
  name: 'clara',
  age: 314.159
};
var people = [clara, bob, alice];
sortByNameCaseInsensitive(people); //=> [alice, bob, clara]

split String

(String | RegExp) → String → [String]
Parameters
  • String sep

    The pattern.

  • String str

    The string to separate into an array.

Returns Array

The array of strings from str separated by str.

Added in v0.1.0

Splits a string into an array of strings based on the given separator.

See also join.
var pathComponents = R.split('/');
R.tail(pathComponents('/usr/local/bin/node')); //=> ['usr', 'local', 'bin', 'node']

R.split('.', 'a.b.c.xyz.d'); //=> ['a', 'b', 'c', 'xyz', 'd']

splitAt List

Number → [a] → [[a], [a]]
Number → String → [String, String]
Parameters
  • Number index

    The index where the array/string is split.

  • Array array

    The array/string to be split.

Returns Array

Added in 0.19.0

Splits a given list or string at a given index.

R.splitAt(1, [1, 2, 3]);          //=> [[1], [2, 3]]
R.splitAt(5, 'hello world');      //=> ['hello', ' world']
R.splitAt(-1, 'foobar');          //=> ['fooba', 'r']

splitEvery List

Number → [a] → [[a]]
Number → String → [String]
Parameters
  • Number n
  • Array list
Returns Array

Added in v0.16.0

Splits a collection into slices of the specified length.

R.splitEvery(3, [1, 2, 3, 4, 5, 6, 7]); //=> [[1, 2, 3], [4, 5, 6], [7]]
R.splitEvery(3, 'foobarbaz'); //=> ['foo', 'bar', 'baz']

splitWhen List

(a → Boolean) → [a] → [[a], [a]]
Parameters
  • function pred

    The predicate that determines where the array is split.

  • Array list

    The array to be split.

Returns Array

Added in 0.19.0

Takes a list and a predicate and returns a pair of lists with the following properties:

  • the result of concatenating the two output lists is equivalent to the input list;
  • none of the elements of the first output list satisfies the predicate; and
  • if the second output list is non-empty, its first element satisfies the predicate.
R.splitWhen(R.equals(2), [1, 2, 3, 1, 2, 3]);   //=> [[1], [2, 3, 1, 2, 3]]

subtract Math

Number → Number → Number
Parameters
  • Number a

    The first value.

  • Number b

    The second value.

Returns Number

The result of a - b.

Added in v0.1.0

Subtracts two numbers. Equivalent to a - b but curried.

See also add.
R.subtract(10, 8); //=> 2

var minus5 = R.subtract(R.__, 5);
minus5(17); //=> 12

var complementaryAngle = R.subtract(90);
complementaryAngle(30); //=> 60
complementaryAngle(72); //=> 18

sum Math

[Number] → Number
Parameters
  • Array list

    An array of numbers

Returns Number

The sum of all the numbers in the list.

Added in v0.1.0

Adds together all the elements of a list.

See also reduce.
R.sum([2,4,6,8,100,1]); //=> 121

symmetricDifference Relation

[*] → [*] → [*]
Parameters
  • Array list1

    The first list.

  • Array list2

    The second list.

Returns Array

The elements in list1 or list2, but not both.

Added in 0.19.0

Finds the set (i.e. no duplicates) of all elements contained in the first or second list, but not both.

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

symmetricDifferenceWith Relation

(a → a → Boolean) → [a] → [a] → [a]
Parameters
  • function pred

    A predicate used to test whether two items are equal.

  • Array list1

    The first list.

  • Array list2

    The second list.

Returns Array

The elements in list1 or list2, but not both.

Added in 0.19.0

Finds the set (i.e. no duplicates) of all elements contained in the first or second list, but not both. Duplication is determined according to the value returned by applying the supplied predicate to two list elements.

var eqA = R.eqBy(R.prop('a'));
var l1 = [{a: 1}, {a: 2}, {a: 3}, {a: 4}];
var l2 = [{a: 3}, {a: 4}, {a: 5}, {a: 6}];
R.symmetricDifferenceWith(eqA, l1, l2); //=> [{a: 1}, {a: 2}, {a: 5}, {a: 6}]

T Function

* → Boolean
Parameters
  • *
Returns Boolean

Added in v0.9.0

A function that always returns true. Any passed in parameters are ignored.

See also always, F.
R.T(); //=> true

tail List

[a] → [a]
String → String
Parameters
  • * list
Returns *

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.
R.tail([1, 2, 3]);  //=> [2, 3]
R.tail([1, 2]);     //=> [2]
R.tail([1]);        //=> []
R.tail([]);         //=> []

R.tail('abc');  //=> 'bc'
R.tail('ab');   //=> 'b'
R.tail('a');    //=> ''
R.tail('');     //=> ''

take List

Number → [a] → [a]
Number → String → String
Parameters
  • Number n
  • * list
Returns *

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.
R.take(1, ['foo', 'bar', 'baz']); //=> ['foo']
R.take(2, ['foo', 'bar', 'baz']); //=> ['foo', 'bar']
R.take(3, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz']
R.take(4, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz']
R.take(3, 'ramda');               //=> 'ram'

var personnel = [
  'Dave Brubeck',
  'Paul Desmond',
  'Eugene Wright',
  'Joe Morello',
  'Gerry Mulligan',
  'Bob Bates',
  'Joe Dodge',
  'Ron Crotty'
];

var takeFive = R.take(5);
takeFive(personnel);
//=> ['Dave Brubeck', 'Paul Desmond', 'Eugene Wright', 'Joe Morello', 'Gerry Mulligan']

takeLast List

Number → [a] → [a]
Number → String → String
Parameters
  • Number n

    The number of elements to return.

  • Array xs

    The collection to consider.

Returns Array

Added in v0.16.0

Returns a new list containing the last n elements of the given list. If n > list.length, returns a list of list.length elements.

See also dropLast.
R.takeLast(1, ['foo', 'bar', 'baz']); //=> ['baz']
R.takeLast(2, ['foo', 'bar', 'baz']); //=> ['bar', 'baz']
R.takeLast(3, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz']
R.takeLast(4, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz']
R.takeLast(3, 'ramda');               //=> 'mda'

takeLastWhile List

(a → Boolean) → [a] → [a]
Parameters
  • function fn

    The function called per iteration.

  • Array list

    The collection to iterate over.

Returns Array

A new array.

Added in v0.16.0

Returns a new list containing the last 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).

See also dropLastWhile, addIndex.
var isNotOne = x => x !== 1;

R.takeLastWhile(isNotOne, [1, 2, 3, 4]); //=> [2, 3, 4]

takeWhile List

(a → Boolean) → [a] → [a]
Parameters
  • function fn

    The function called per iteration.

  • Array list

    The 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.

var isNotFour = x => x !== 4;

R.takeWhile(isNotFour, [1, 2, 3, 4, 3, 2, 1]); //=> [1, 2, 3]

tap Function

(a → *) → a → a
Parameters
  • function fn

    The function to call with x. The return value of fn will be thrown away.

  • * x
Returns *

x.

Added in v0.1.0

Runs the given function with the supplied object, then returns the object.

var sayX = x => console.log('x is ' + x);
R.tap(sayX, 100); //=> 100
//-> 'x is 100'

test String

RegExp → String → Boolean
Parameters
  • RegExp pattern
  • String str
Returns Boolean

Added in v0.12.0

Determines whether a given string matches a given regular expression.

See also match.
R.test(/^x/, 'xyz'); //=> true
R.test(/^y/, 'xyz'); //=> false

times List

(Number → a) → Number → [a]
Parameters
  • function fn

    The function to invoke. Passed one argument, the current value of n.

  • Number n

    A 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.

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

toLower String

String → String
Parameters
  • String str

    The string to lower case.

Returns String

The lower case version of str.

Added in v0.9.0

The lower case version of a string.

See also toUpper.
R.toLower('XYZ'); //=> 'xyz'

toPairs Object

{String: *} → [[String,*]]
Parameters
  • Object obj

    The object to extract from

Returns Array

An array of key, value arrays from the object's own properties.

Added in v0.4.0

Converts an object into an array of key, value arrays. Only the object's own properties are used. Note that the order of the output array is not guaranteed to be consistent across different JS platforms.

See also fromPairs.
R.toPairs({a: 1, b: 2, c: 3}); //=> [['a', 1], ['b', 2], ['c', 3]]

toPairsIn Object

{String: *} → [[String,*]]
Parameters
  • Object obj

    The object to extract from

Returns Array

An array of key, value arrays from the object's own and prototype properties.

Added in v0.4.0

Converts an object into an array of key, value arrays. The object's own properties and prototype properties are used. Note that the order of the output array is not guaranteed to be consistent across different JS platforms.

var F = function() { this.x = 'X'; };
F.prototype.y = 'Y';
var f = new F();
R.toPairsIn(f); //=> [['x','X'], ['y','Y']]

toString String

* → String
Parameters
  • * val
Returns String

Added in v0.14.0

Returns the string representation of the given value. eval'ing the output should result in a value equivalent to the input value. Many of the built-in toString methods do not satisfy this requirement.

If the given value is an [object Object] with a toString method other than Object.prototype.toString, this method is invoked with no arguments to produce the return value. This means user-defined constructor functions can provide a suitable toString method. For example:

function Point(x, y) {
  this.x = x;
  this.y = y;
}

Point.prototype.toString = function() {
  return 'new Point(' + this.x + ', ' + this.y + ')';
};

R.toString(new Point(1, 2)); //=> 'new Point(1, 2)'
R.toString(42); //=> '42'
R.toString('abc'); //=> '"abc"'
R.toString([1, 2, 3]); //=> '[1, 2, 3]'
R.toString({foo: 1, bar: 2, baz: 3}); //=> '{"bar": 2, "baz": 3, "foo": 1}'
R.toString(new Date('2001-02-03T04:05:06Z')); //=> 'new Date("2001-02-03T04:05:06.000Z")'

toUpper String

String → String
Parameters
  • String str

    The string to upper case.

Returns String

The upper case version of str.

Added in v0.9.0

The upper case version of a string.

See also toLower.
R.toUpper('abc'); //=> 'ABC'

transduce List

(c → c) → (a,b → a) → a → [b] → a
Parameters
  • function xf

    The transducer function. Receives a transformer and returns a transformer.

  • function fn

    The iterator function. Receives two values, the accumulator and the current element from the array. Wrapped as transformer, if necessary, and used to initialize the transducer

  • * acc

    The initial accumulator value.

  • Array list

    The list to iterate over.

Returns *

The final, accumulated value.

Added in v0.12.0

Initializes a transducer using supplied iterator function. Returns a single item by iterating through the list, successively calling the transformed 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 will be wrapped as a transformer to initialize the transducer. A transformer can be passed directly in place of an iterator function. In both cases, iteration may be stopped early with the R.reduced function.

A transducer is a function that accepts a transformer and returns a transformer and can be composed directly.

A transformer is an an object that provides a 2-arity reducing iterator function, step, 0-arity initial value function, init, and 1-arity result extraction function, result. The step function is used as the iterator function in reduce. The result function is used to convert the final accumulator into the return type and in most cases is R.identity. The init function can be used to provide an initial accumulator, but is ignored by transduce.

The iteration is performed with R.reduce after initializing the transducer.

See also reduce, reduced, into.
var numbers = [1, 2, 3, 4];
var transducer = R.compose(R.map(R.add(1)), R.take(2));

R.transduce(transducer, R.flip(R.append), [], numbers); //=> [2, 3]

transpose List

[[a]] → [[a]]
Parameters
  • Array list

    A 2D list

Returns Array

A 2D list

Added in 0.19.0

Transposes the rows and columns of a 2D list. When passed a list of n lists of length x, returns a list of x lists of length n.

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

If some of the rows are shorter than the following rows, their elements are skipped:

R.transpose([[10, 11], [20], [], [30, 31, 32]]) //=> [[10, 20, 30], [11, 31], [32]]

traverse List

(Applicative f, Traversable t) => (a → f a) → (a → f b) → t a → f (t b)
Parameters
  • function of
  • function f
  • * traversable
Returns *

Added in 0.19.0

Maps an Applicative-returning function over a Traversable, then uses sequence to transform the resulting Traversable of Applicative into an Applicative of Traversable.

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

See also sequence.
R.traverse(Maybe.of, R.negate, [Just(1), Just(2), Just(3)]);   //=> Just([-1, -2, -3])
R.traverse(Maybe.of, R.negate, [Just(1), Just(2), Nothing()]); //=> Nothing()

R.traverse(R.of, R.negate, Just([1, 2, 3])); //=> [Just(-1), Just(-2), Just(-3)]
R.traverse(R.of, R.negate, Nothing());       //=> [Nothing()]

trim String

String → String
Parameters
  • String str

    The string to trim.

Returns String

Trimmed version of str.

Added in v0.6.0

Removes (strips) whitespace from both ends of the string.

R.trim('   xyz  '); //=> 'xyz'
R.map(R.trim, R.split(',', 'x, y, z')); //=> ['x', 'y', 'z']

type Type

(* → {*}) → String
Parameters
  • * val

    The value to test

Returns String

Added in v0.8.0

Gives a single-word string description of the (native) type of a value, returning such answers as 'Object', 'Number', 'Array', or 'Null'. Does not attempt to distinguish user Object types any further, reporting them all as 'Object'.

R.type({}); //=> "Object"
R.type(1); //=> "Number"
R.type(false); //=> "Boolean"
R.type('s'); //=> "String"
R.type(null); //=> "Null"
R.type([]); //=> "Array"
R.type(/[A-z]/); //=> "RegExp"

unapply Function

([*…] → a) → (*… → a)
Parameters
  • function fn
Returns function

Added in v0.8.0

Takes a function fn, which takes a single array argument, and returns a function which:

  • takes any number of positional arguments;
  • passes these arguments to fn as an array; and
  • returns the result.

In other words, R.unapply derives a variadic function from a function which takes an array. R.unapply is the inverse of R.apply.

See also apply.
R.unapply(JSON.stringify)(1, 2, 3); //=> '[1,2,3]'

unary Function

(* → b) → (a → b)
Parameters
  • function fn

    The function to wrap.

Returns function

A new function wrapping fn. The new function is guaranteed to be of arity 1.

Added in v0.2.0

Wraps a function of any arity (including nullary) in a function that accepts exactly 1 parameter. Any extraneous parameters will not be passed to the supplied function.

var takesTwoArgs = function(a, b) {
  return [a, b];
};
takesTwoArgs.length; //=> 2
takesTwoArgs(1, 2); //=> [1, 2]

var takesOneArg = R.unary(takesTwoArgs);
takesOneArg.length; //=> 1
// Only 1 argument is passed to the wrapped function
takesOneArg(1, 2); //=> [1, undefined]

uncurryN Function

Number → (a → b) → (a → c)
Parameters
  • Number length

    The arity for the returned function.

  • function fn

    The function to uncurry.

Returns function

A new function.

Added in v0.14.0

Returns a function of arity n from a (manually) curried function.

See also curry.
var addFour = a => b => c => d => a + b + c + d;

var uncurriedAddFour = R.uncurryN(4, addFour);
uncurriedAddFour(1, 2, 3, 4); //=> 10

unfold List

(a → [b]) → * → [b]
Parameters
  • function fn

    The iterator function. receives one argument, seed, and returns either false to quit iteration or an array of length two to proceed. The element at index 0 of this array will be added to the resulting array, and the element at index 1 will be passed to the next call to fn.

  • * seed

    The seed value.

Returns Array

The final list.

Added in v0.10.0

Builds a list from a seed value. Accepts an iterator function, which returns either false to stop iteration or an array of length 2 containing the value to add to the resulting list and the seed to be used in the next call to the iterator function.

The iterator function receives one argument: (seed).

var f = n => n > 50 ? false : [-n, n + 10];
R.unfold(f, 10); //=> [-10, -20, -30, -40, -50]

union Relation

[*] → [*] → [*]
Parameters
  • Array as

    The first list.

  • Array bs

    The second list.

Returns Array

The first and second lists concatenated, with duplicates removed.

Added in v0.1.0

Combines two lists into a set (i.e. no duplicates) composed of the elements of each list.

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

unionWith Relation

(a → a → Boolean) → [*] → [*] → [*]
Parameters
  • function pred

    A predicate used to test whether two items are equal.

  • Array list1

    The first list.

  • Array list2

    The second list.

Returns Array

The first and second lists concatenated, with duplicates removed.

Added in v0.1.0

Combines two lists into a set (i.e. no duplicates) composed of the elements of each list. Duplication is determined according to the value returned by applying the supplied predicate to two list elements.

See also union.
var l1 = [{a: 1}, {a: 2}];
var l2 = [{a: 1}, {a: 4}];
R.unionWith(R.eqBy(R.prop('a')), l1, l2); //=> [{a: 1}, {a: 2}, {a: 4}]

uniq List

[a] → [a]
Parameters
  • Array list

    The 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.

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

uniqBy List

(a → b) → [a] → [a]
Parameters
  • function fn

    A function used to produce a value to use during comparisons.

  • Array list

    The array to consider.

Returns Array

The list of unique items.

Added in v0.16.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 function to each list element. Prefers the first item if the supplied function produces the same value on two items. R.equals is used for comparison.

R.uniqBy(Math.abs, [-1, -5, 2, 10, 1, 2]); //=> [-1, -5, 2, 10]

uniqWith List

(a, a → Boolean) → [a] → [a]
Parameters
  • function pred

    A predicate used to test whether two items are equal.

  • Array list

    The 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.

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

unless Logic

(a → Boolean) → (a → a) → a → a
Parameters
  • function pred

    A predicate function

  • function whenFalseFn

    A function to invoke when the pred evaluates to a falsy value.

  • * x

    An object to test with the pred function and pass to whenFalseFn if necessary.

Returns *

Either x or the result of applying x to whenFalseFn.

Added in v0.18.0

Tests the final argument by passing it to the given predicate function. If the predicate is not satisfied, the function will return the result of calling the whenFalseFn function with the same argument. If the predicate is satisfied, the argument is returned as is.

See also ifElse, when.
// coerceArray :: (a|[a]) -> [a]
var coerceArray = R.unless(R.isArrayLike, R.of);
coerceArray([1, 2, 3]); //=> [1, 2, 3]
coerceArray(1);         //=> [1]

unnest List

Chain c => c (c a) → c a
Parameters
  • * list
Returns *

Added in v0.3.0

Shorthand for R.chain(R.identity), which removes one level of nesting from any Chain.

See also flatten, chain.
R.unnest([1, [2], [[3]]]); //=> [1, 2, [3]]
R.unnest([[1, 2], [3, 4], [5, 6]]); //=> [1, 2, 3, 4, 5, 6]

update List

Number → a → [a] → [a]
Parameters
  • Number idx

    The index to update.

  • * x

    The value to exist at the given index of the returned array.

  • Array list

    The source array-like object to be updated.

Returns Array

A copy of list with the value at index idx replaced with x.

Added in v0.14.0

Returns a new copy of the array with the element at the provided index replaced with the given value.

See also adjust.
R.update(1, 11, [0, 1, 2]);     //=> [0, 11, 2]
R.update(1)(11)([0, 1, 2]);     //=> [0, 11, 2]

useWith Function

(x1 → x2 → … → z) → [(a → x1), (b → x2), …] → (a → b → … → z)
Parameters
  • function fn

    The function to wrap.

  • Array transformers

    A list of transformer functions

Returns function

The wrapped function.

Added in v0.1.0

Accepts a function fn and a list of transformer functions and returns a new curried function. When the new function is invoked, it calls the function fn with parameters consisting of the result of calling each supplied handler on successive arguments to the new function.

If more arguments are passed to the returned function than transformer functions, those arguments are passed directly to fn as additional parameters. If you expect additional arguments that don't need to be transformed, although you can ignore them, it's best to pass an identity function so that the new function reports the correct arity.

R.useWith(Math.pow, [R.identity, R.identity])(3, 4); //=> 81
R.useWith(Math.pow, [R.identity, R.identity])(3)(4); //=> 81
R.useWith(Math.pow, [R.dec, R.inc])(3, 4); //=> 32
R.useWith(Math.pow, [R.dec, R.inc])(3)(4); //=> 32

values Object

{k: v} → [v]
Parameters
  • Object obj

    The object to extract values from

Returns Array

An array of the values of the object's own properties.

Added in v0.1.0

Returns a list of all the enumerable own properties of the supplied object. Note that the order of the output array is not guaranteed across different JS platforms.

R.values({a: 1, b: 2, c: 3}); //=> [1, 2, 3]

valuesIn Object

{k: v} → [v]
Parameters
  • Object obj

    The object to extract values from

Returns Array

An array of the values of the object's own and prototype properties.

Added in v0.2.0

Returns a list of all the properties, including prototype properties, of the supplied object. Note that the order of the output array is not guaranteed to be consistent across different JS platforms.

var F = function() { this.x = 'X'; };
F.prototype.y = 'Y';
var f = new F();
R.valuesIn(f); //=> ['X', 'Y']

view Object

Lens s a → s → a
Lens s a = Functor f => (a → f a) → s → f s
Parameters
  • Lens lens
  • * x
Returns *

Added in v0.16.0

Returns a "view" of the given data structure, determined by the given lens. The lens's focus determines which portion of the data structure is visible.

See also prop, lensIndex, lensProp.
var xLens = R.lensProp('x');

R.view(xLens, {x: 1, y: 2});  //=> 1
R.view(xLens, {x: 4, y: 2});  //=> 4

when Logic

(a → Boolean) → (a → a) → a → a
Parameters
  • function pred

    A predicate function

  • function whenTrueFn

    A function to invoke when the condition evaluates to a truthy value.

  • * x

    An object to test with the pred function and pass to whenTrueFn if necessary.

Returns *

Either x or the result of applying x to whenTrueFn.

Added in v0.18.0

Tests the final argument by passing it to the given predicate function. If the predicate is satisfied, the function will return the result of calling the whenTrueFn function with the same argument. If the predicate is not satisfied, the argument is returned as is.

See also ifElse, unless.
// truncate :: String -> String
var truncate = R.when(
  R.propSatisfies(R.gt(R.__, 10), 'length'),
  R.pipe(R.take(10), R.append('…'), R.join(''))
);
truncate('12345');         //=> '12345'
truncate('0123456789ABC'); //=> '0123456789…'

where Object

{String: (* → Boolean)} → {String: *} → Boolean
Parameters
  • Object spec
  • Object testObj
Returns Boolean

Added in v0.1.1

Takes a spec object and a test object; returns true if the test satisfies the spec. Each of the spec's own properties must be a predicate function. Each predicate is applied to the value of the corresponding property of the test object. where returns true if all the predicates return true, false otherwise.

where is well suited to declaratively expressing constraints for other functions such as filter and find.

// pred :: Object -> Boolean
var pred = R.where({
  a: R.equals('foo'),
  b: R.complement(R.equals('bar')),
  x: R.gt(_, 10),
  y: R.lt(_, 20)
});

pred({a: 'foo', b: 'xxx', x: 11, y: 19}); //=> true
pred({a: 'xxx', b: 'xxx', x: 11, y: 19}); //=> false
pred({a: 'foo', b: 'bar', x: 11, y: 19}); //=> false
pred({a: 'foo', b: 'xxx', x: 10, y: 19}); //=> false
pred({a: 'foo', b: 'xxx', x: 11, y: 20}); //=> false

whereEq Object

{String: *} → {String: *} → Boolean
Parameters
  • Object spec
  • Object testObj
Returns Boolean

Added in v0.14.0

Takes a spec object and a test object; returns true if the test satisfies the spec, false otherwise. An object satisfies the spec if, for each of the spec's own properties, accessing that property of the object gives the same value (in R.equals terms) as accessing that property of the spec.

whereEq is a specialization of where.

See also where.
// pred :: Object -> Boolean
var pred = R.whereEq({a: 1, b: 2});

pred({a: 1});              //=> false
pred({a: 1, b: 2});        //=> true
pred({a: 1, b: 2, c: 3});  //=> true
pred({a: 1, b: 1});        //=> false

without List

[a] → [a] → [a]
Parameters
  • Array list1

    The values to be removed from list2.

  • Array list2

    The array to remove values from.

Returns Array

The new array without values in list1.

Added in 0.19.0

Returns a new list without values in the first argument. R.equals is used to determine equality.

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

See also transduce.
R.without([1, 2], [1, 2, 1, 3, 4]); //=> [3, 4]

wrap Function

(a… → b) → ((a… → b) → a… → c) → (a… → c)
Parameters
  • function fn

    The function to wrap.

  • function wrapper

    The wrapper function.

Returns function

The wrapped function.

Added in v0.1.0

Wrap a function inside another to allow you to make adjustments to the parameters, or do other processing either before the internal function is called or with its results.

var greet = name => 'Hello ' + name;

var shoutedGreet = R.wrap(greet, (gr, name) => gr(name).toUpperCase());

shoutedGreet("Kathy"); //=> "HELLO KATHY"

var shortenedGreet = R.wrap(greet, function(gr, name) {
  return gr(name.substring(0, 3));
});
shortenedGreet("Robert"); //=> "Hello Rob"

xprod List

[a] → [b] → [[a,b]]
Parameters
  • Array as

    The first list.

  • Array bs

    The 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.

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

zip List

[a] → [b] → [[a,b]]
Parameters
  • Array list1

    The first array to consider.

  • Array list2

    The 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] }).

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

zipObj List

[String] → [*] → {String: *}
Parameters
  • Array keys

    The array that will be properties on the output object.

  • Array values

    The list of values on the output object.

Returns Object

The object made by pairing up same-indexed elements of keys and values.

Added in v0.3.0

Creates a new object out of a list of keys and a list of values.

R.zipObj(['a', 'b', 'c'], [1, 2, 3]); //=> {a: 1, b: 2, c: 3}

zipWith List

(a,b → c) → [a] → [b] → [c]
Parameters
  • function fn

    The function used to combine the two elements into one value.

  • Array list1

    The first array to consider.

  • Array list2

    The 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.

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