Classes
Methods
(static) allEqual(list) → {boolean}
- Source:
- Since:
- Signature:
-
[a] -> Boolean
- Category:
-
- List
- See also:
Returns true if all items in the list are equivalent using R.equals
for equality comparisons.
Example
RA.allEqual([ 1, 2, 3, 4 ]); //=> false
RA.allEqual([ 1, 1, 1, 1 ]); //=> true
RA.allEqual([]); //=> true
Parameters:
Name | Type | Description |
---|---|---|
list |
Array | The list of values |
Returns:
- Type
- boolean
(static) allEqualTo(val, list) → {boolean}
- Source:
- Since:
- Signature:
-
a -> [b] -> Boolean
- Category:
-
- List
- See also:
Returns true if all items in the list are equivalent to user provided value using R.equals
for equality comparisons.
Example
RA.allEqualTo(1, [ 1, 2, 3, 4 ]); //=> false
RA.allEqualTo(1, [ 1, 1, 1, 1 ]); //=> true
RA.allEqualTo({}, [ {}, {} ]); //=> true
RA.allEqualTo(1, []); //=> true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | User provided value to check the |
list |
Array | The list of values |
Returns:
- Type
- boolean
(static) allIdentical(list) → {boolean}
- Source:
- Since:
- Signature:
-
[a] -> Boolean
- Category:
-
- List
- See also:
Returns true if all items in the list are equivalent using R.identical
for equality comparisons.
Example
RA.allIdentical([ 1, 2, 3, 4 ]); //=> false
RA.allIdentical([ 1, 1, 1, 1 ]); //=> true
RA.allIdentical([]); //=> true
RA.allIdentical([ {}, {} ]); //=> false
RA.allIdentical([ () => {}, () => {} ]); //=> false
Parameters:
Name | Type | Description |
---|---|---|
list |
Array | The list of values |
Returns:
- Type
- boolean
(static) allIdenticalTo(val, list) → {boolean}
- Source:
- Since:
- Signature:
-
a -> [b] -> Boolean
- Category:
-
- List
- See also:
Returns true if all items in the list are equivalent to user provided value using R.identical
for equality comparisons.
Example
RA.allIdenticalTo(1, [ 1, 2, 3, 4 ]); //=> false
RA.allIdenticalTo(1, [ 1, 1, 1, 1 ]); //=> true
RA.allIdenticalTo(1, []); //=> true
RA.allIdenticalTo({}, [ {}, {} ]); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | User provided value to check the |
list |
Array | The list of values |
Returns:
- Type
- boolean
(static) allP(iterable) → {Promise}
- Source:
- Since:
- Signature:
-
[Promise a] -> Promise [a]
- Category:
-
- Function
- See also:
Composable shortcut for Promise.all
.
The allP
method returns a single Promise that resolves when all of the promises
in the iterable argument have resolved or when the iterable argument contains no promises.
It rejects with the reason of the first promise that rejects.
Example
RA.allP([1, 2]); //=> Promise([1, 2])
RA.allP([1, Promise.resolve(2)]); //=> Promise([1, 2])
RA.allP([Promise.resolve(1), Promise.resolve(2)]); //=> Promise([1, 2])
RA.allP([1, Promise.reject(2)]); //=> Promise(2)
Parameters:
Name | Type | Description |
---|---|---|
iterable |
Iterable.<*> | An iterable object such as an Array or String |
Returns:
An already resolved Promise if the iterable passed is empty. An asynchronously resolved Promise if the iterable passed contains no promises. Note, Google Chrome 58 returns an already resolved promise in this case. A pending Promise in all other cases. This returned promise is then resolved/rejected asynchronously (as soon as the stack is empty) when all the promises in the given iterable have resolved, or if any of the promises reject. See the example about "Asynchronicity or synchronicity of allP" below.
- Type
- Promise
(static) allSettledP(iterable) → {Promise}
- Source:
- Since:
- Signature:
-
[Promise a] -> Promise [Settlement a]
-
Settlement = { status: String, value: * }
- Category:
-
- Function
- See also:
Returns a promise that is fulfilled with an array of promise state snapshots, but only after all the original promises have settled, i.e. become either fulfilled or rejected. We say that a promise is settled if it is not pending, i.e. if it is either fulfilled or rejected.
Example
RA.allSettledP([
Promise.resolve(1),
2,
Promise.reject(3),
]); //=> Promise([{ status: 'fulfilled', value: 1 }, { status: 'fulfilled', value: 2 }, { status: 'rejected', reason: 3 }])
Parameters:
Name | Type | Description |
---|---|---|
iterable |
Iterable.<*> | An iterable object such as an Array or String |
Returns:
Returns a promise that is fulfilled with an array of promise state snapshots
- Type
- Promise
(static) allUnique(list) → {boolean}
- Source:
- Since:
- Signature:
-
[a] -> Boolean
- Category:
-
- List
- See also:
Returns true if all items in the list are unique. R.equals
is used to determine equality.
Example
RA.allUnique([ 1, 2, 3, 4 ]); //=> true
RA.allUnique([ 1, 1, 2, 3 ]); //=> false
RA.allUnique([]); //=> true
Parameters:
Name | Type | Description |
---|---|---|
list |
Array | The list of values |
Returns:
- Type
- boolean
(static) anyP(iterable) → {Promise}
- Source:
- Since:
- Signature:
-
[Promise a] -> Promise a
- Category:
-
- Function
- See also:
Returns a promise that is fulfilled by the first given promise to be fulfilled, or rejected with an array of rejection reasons if all of the given promises are rejected.
Example
RA.anyP([
Promise.resolve(1),
2,
Promise.reject(3),
]); //=> Promise(1)
Parameters:
Name | Type | Description |
---|---|---|
iterable |
Iterable.<*> | An iterable object such as an Array or String |
Returns:
A promise that is fulfilled by the first given promise to be fulfilled, or rejected with an array of rejection reasons if all of the given promises are rejected
- Type
- Promise
(static) appendFlipped(list, el) → {Array}
- Source:
- Since:
- Signature:
-
[a] -> a -> [a]
- Category:
-
- List
- See also:
Returns a new list containing the contents of the given list, followed by the given element. Like R.append but with argument order reversed.
Example
RA.appendFlipped(['write', 'more'], 'tests'); //=> ['write', 'more', 'tests']
RA.appendFlipped([], 'tests'); //=> ['tests']
RA.appendFlipped(['write', 'more'], ['tests']); //=> ['write', 'more', ['tests']]
Parameters:
Name | Type | Description |
---|---|---|
list |
Array | The list of elements to add a new item to |
el |
* | The element to add to the end of the new list |
Returns:
A new list containing the elements of the old list followed by el
- Type
- Array
(static) argsPass(combiningPredicate, functions) → {boolean}
- Source:
- Since:
- Signature:
-
((* -> Boolean) -> [*] -> Boolean) -> [(* -> Boolean), ...] -> (*...) -> Boolean
- Category:
-
- Logic
Takes a combining predicate and a list of functions and returns a function which will map the
arguments it receives to the list of functions and returns the result of passing the values
returned from each function to the combining predicate. A combining predicate is a function that
combines a list of Boolean values into a single Boolean value, such as R.any
or R.all
. It
will test each value using RA.isTruthy
, meaning the functions don't necessarily have to be
predicates.
The function returned is curried to the number of functions supplied, and if called with more arguments than functions, any remaining arguments are passed in to the combining predicate untouched.
Example
RA.argsPass(R.all, [RA.isArray, RA.isBoolean, RA.isString])([], false, 'abc') //=> true
RA.argsPass(R.all, [RA.isArray, RA.isBoolean, RA.isString])([], false, 1) //=> false
RA.argsPass(R.any, [RA.isArray, RA.isBoolean, RA.isString])({}, 1, 'abc') //=> true
RA.argsPass(R.any, [RA.isArray, RA.isBoolean, RA.isString])({}, 1, false) //=> false
RA.argsPass(R.none, [RA.isArray, RA.isBoolean, RA.isString])({}, 1, false) //=> true
RA.argsPass(R.none, [RA.isArray, RA.isBoolean, RA.isString])({}, 1, 'abc') //=> false
Parameters:
Name | Type | Description |
---|---|---|
combiningPredicate |
function | The predicate used to combine the values returned from the list of functions |
functions |
Array | List of functions |
Returns:
Returns the combined result of mapping arguments to functions
- Type
- boolean
(static) async(generatorFn) → {function}
- Source:
- Since:
- Signature:
-
Promise c => (a, b, ...) -> a -> b -> ... -> c
- Category:
-
- Function
- See also:
Takes a generator function and returns an async function. The async function returned is a curried function whose arity matches that of the generator function.
Note: This function is handy for environments that does support generators but doesn't support async/await.
Example
const asyncFn = RA.async(function* generator(val1, val2) {
const a = yield Promise.resolve(val1);
const b = yield Promise.resolve(val2);
return a + b;
});
asyncFn(1, 2); //=> Promise(3)
Parameters:
Name | Type | Description |
---|---|---|
generatorFn |
function | The generator function |
Returns:
Curried async function
- Type
- function
(static) cata(leftFn, rightFn, catamorphicObj) → {*}
- Source:
- Since:
- Signature:
-
(a -> b) -> (a -> c) -> Cata a -> b | c
- Category:
-
- Function
- See also:
The catamorphism is a way of folding a type into a value.
Either
If the either is right then the right function will be executed with
the right
value and the value of the function returned. Otherwise the left function
will be called with the left
value.
Maybe
If the maybe is Some than the right function will be executed with the some
value and the value of the function
returned. Otherwise the left function with be called without an argument.
Result
If the result is Ok than the right function will be executed with the Ok
value and the value of the function
returned. Otherwise the left function will be called with the Error
value.
Validation
If the validation is Success than the right function will be executed with the Success
value and the value of the function
returned. Otherwise the left function will be called with the Failure
value.
Supported monadic libraries: monet.js, folktale, ramda-fantasy
Example
// Either
const eitherR = Either.Right(1);
const eitherL = Either.Left(2);
RA.cata(identity, identity, eitherR); //=> 1
RA.cata(identity, identity, eitherL); //=> 2
// Maybe
const maybeSome = Maybe.Some(1);
const maybeNothing = Maybe.Nothing();
RA.cata(identity, identity, maybeSome); //=> 1
RA.cata(identity, identity, maybeNothing); //=> undefined
Parameters:
Name | Type | Description |
---|---|---|
leftFn |
function | The left function that consumes the left value |
rightFn |
function | The right function that consumes the right value |
catamorphicObj |
Cata | Either, Maybe or any other type with catamorphic capabilities ( |
Returns:
- Type
- *
(static) catchP(onRejected, promise) → {Promise}
- Source:
- Since:
- Signature:
-
(a -> Promise b | b) -> Promise b
- Category:
-
- Function
- See also:
Composable shortcut for Promise.catch
.
The catchP function returns a Promise. It takes two arguments: a callback function for the failure of the Promise
and the promise instance itself.
Example
RA.catchP(() => 'b', Promise.resolve('a')); //=> Promise('a')
RA.catchP(() => 'b', Promise.reject('a')); //=> Promise('b')
Parameters:
Name | Type | Description |
---|---|---|
onRejected |
function | A Function called if the Promise is rejected. This function has one argument, the rejection reason. |
promise |
Promise | Any Promise |
Returns:
Returns a Promise with dealt rejected cases
- Type
- Promise
(static) ceil(number) → {number}
Returns the smallest integer greater than or equal to a given number.
Note: ceil(null) returns integer 0 and does not give a NaN error.
Example
RA.ceil(.95); //=> 1
RA.ceil(4); //=> 4
RA.ceil(7.004); //=> 8
RA.ceil(-0.95); //=> -0
RA.ceil(-4); //=> -4
RA.ceil(-7.004); //=> -7
RA.ceil(null); //=> 0
Parameters:
Name | Type | Description |
---|---|---|
number |
number | The number to ceil |
Returns:
The smallest integer greater than or equal to the given number
- Type
- number
(static) compact(list) → {Array}
- Source:
- Since:
- Signature:
-
Filterable f => f a -> f a
- Category:
-
- List
- See also:
Creates an array with all falsy values removed. The values false, null, 0, "", undefined, and NaN are falsy.
Example
RA.compact([0, 1, false, 2, '', 3]); //=> [1, 2, 3]
Parameters:
Name | Type | Description |
---|---|---|
list |
Array | The array to compact |
Returns:
Returns the new array of filtered values
- Type
- Array
(static) concatAll(list) → {Array|string|undefined}
- Source:
- Since:
- Signature:
-
[[a]] -> [a] | Undefined
[String] -> String | Undefined
Semigroup s => Foldable s f => f -> s | Undefined
- Category:
-
- List
- See also:
Returns the result of concatenating the given lists or strings. Note: RA.concatAll expects all elements to be of the same type. It will throw an error if you concat an Array with a non-Array value. Dispatches to the concat method of the preceding element, if present. Can also concatenate multiple elements of a fantasy-land compatible semigroup. Returns undefined if empty array was passed.
Example
concatAll([[1], [2], [3]]); //=> [1, 2, 3]
concatAll(['1', '2', '3']); //=> '123'
concatAll([]); //=> undefined;
Parameters:
Name | Type | Description |
---|---|---|
list |
Array.<(Array|string)> | List containing elements that will be concatenated |
Returns:
Concatenated elements
- Type
- Array | string | undefined
(static) concatRight(firstList, secondList) → {Array|String}
- Source:
- Since:
- Signature:
-
[a] -> [a] -> [a]
String -> String -> String
- Category:
-
- List
- See also:
Returns the result of concatenating the given lists or strings.
Note: R.concat expects both arguments to be of the same type, unlike the native Array.prototype.concat method. It will throw an error if you concat an Array with a non-Array value. Dispatches to the concat method of the second argument, if present.
Example
RA.concatRight('ABC', 'DEF'); //=> 'DEFABC'
RA.concatRight([4, 5, 6], [1, 2, 3]); //=> [1, 2, 3, 4, 5, 6]
RA.concatRight([], []); //=> []
Parameters:
Name | Type | Description |
---|---|---|
firstList |
Array | String | The first list |
secondList |
Array | String | The second list |
Returns:
A list consisting of the elements of secondList
followed by the elements of firstList
.
- Type
- Array | String
(static) contained(list, a) → {boolean}
- Source:
- Since:
- Deprecated:
- since v2.12.0; please use RA.included alias
- Signature:
-
[a] -> a -> Boolean
- Aliases:
-
- included
- Category:
-
- List
- See also:
Returns true if the specified value is equal, in R.equals terms, to at least one element of the given list or false otherwise. Given list can be a string.
Like R.contains but with argument order reversed.
Example
RA.contained([1, 2, 3], 3); //=> true
RA.contained([1, 2, 3], 4); //=> false
RA.contained([{ name: 'Fred' }], { name: 'Fred' }); //=> true
RA.contained([[42]], [42]); //=> true
Parameters:
Name | Type | Description |
---|---|---|
list |
Array | String | The list to consider |
a |
* | The item to compare against |
Returns:
Returns Boolean true
if an equivalent item is in the list or false
otherwise
- Type
- boolean
(static) copyKeys(keysMapnon-null, objnon-null) → (non-null) {Object}
- Source:
- Signature:
-
{a: b} -> {a: *} -> {b: *}
- Category:
-
- Object
- See also:
Creates a new object with the own properties of the provided object, and the
keys copied according to the keysMap object as {oldKey: newKey}
.
When no key from the keysMap is found, then a shallow clone of an object is returned.
Keep in mind that in the case of keys conflict is behaviour undefined and the result may vary between various JS engines!
Example
copyKeys({ a: 'b' }, { a: true }); //=> { a: true, b: true }
copyKeys({ a: 'b' }, { a: true, b: false }); //=> { a: true, b: true }
Parameters:
Name | Type | Description |
---|---|---|
keysMap |
Object | |
obj |
Object |
Returns:
New object with copied keys
- Type
- Object
(static) curryRight(fn) → {function}
- Source:
- Since:
- Signature:
-
(* -> a) -> (* -> a)
- Category:
-
- Function
- See also:
Returns a curried equivalent of the provided function. This function is like curry, except that the provided arguments order is reversed.
Example
const concatStrings = (a, b, c) => a + b + c;
const concatStringsCurried = RA.curryRight(concatStrings);
concatStringCurried('a')('b')('c'); // => 'cba'
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | The function to curry |
Returns:
A new, curried function
- Type
- function
(static) curryRightN(length, fn) → {function}
- Source:
- Since:
- Signature:
-
Number -> (* -> a) -> (* -> a)
- Category:
-
- Function
- See also:
Returns a curried equivalent of the provided function, with the specified arity. This function is like curryN, except that the provided arguments order is reversed.
Example
const concatStrings = (a, b, c) => a + b + c;
const concatStringsCurried = RA.curryRightN(3, concatStrings);
concatStringCurried('a')('b')('c'); // => 'cba'
Parameters:
Name | Type | Description |
---|---|---|
length |
number | The arity for the returned function |
fn |
function | The function to curry |
Returns:
A new, curried function
- Type
- function
(static) defaultWhen(predicatenon-null, defaultVal, val) → {*}
- Source:
- Since:
- Signature:
-
(a -> Boolean) -> b -> a -> a | b
- Category:
-
- Logic
- See also:
Returns the second argument if predicate function returns true
,
otherwise the third argument is returned.
Example
RA.defaultWhen(RA.isNull, 1, null); // => 1
RA.defaultWhen(RA.isNull, 1, 2); // => 2
Parameters:
Name | Type | Description |
---|---|---|
predicate |
function | The predicate function |
defaultVal |
* | The default value |
val |
* |
|
Returns:
The val
if predicate returns false
, otherwise the default value
- Type
- *
(static) delayP(milliseconds) → {Promise}
- Source:
- Signature:
-
Number -> Promise Undefined
{timeout: Number, value: a} -> Promise a
- Category:
-
- Function
Creates a promise which resolves/rejects after the specified milliseconds.
Example
RA.delayP(200); //=> Promise(undefined)
RA.delayP({ timeout: 1000, value: 'hello world' }); //=> Promise('hello world')
RA.delayP.reject(100); //=> Promise(undefined)
RA.delayP.reject({ timeout: 100, value: new Error('error') }); //=> Promise(Error('error'))
Parameters:
Name | Type | Description |
---|---|---|
milliseconds |
number | Object | number of milliseconds or options object |
Returns:
A Promise that is resolved/rejected with the given value (if provided) after the specified delay
- Type
- Promise
(static) dispatch(functionsnon-null) → {*|undefined}
- Source:
- Since:
- Signature:
-
[((a, b, ...) -> x1), ((a, b, ...) -> x2), ...] -> x1 | x2 | ...
- Category:
-
- Function
- See also:
Can be used as a way to compose multiple invokers together to form polymorphic functions, or functions that exhibit different behaviors based on their argument(s). Consumes dispatching functions and keep trying to invoke each in turn, until a non-nil value is returned.
Accepts a list of dispatching functions and returns a new function. When invoked, this new function is applied to some arguments, each dispatching function is applied to those same arguments until one of the dispatching functions returns a non-nil value.
Example
// returns first non-nil value
const stubNil = () => null;
const stubUndefined = () => undefined;
const addOne = v => v + 1;
const addTwo = v => v + 2;
RA.dispatch([stubNil, stubUndefined, addOne, addTwo])(1); //=> 2
// acts as a switch
const fnSwitch = RA.dispatch([
R.ifElse(RA.isString, s => `${s}-join`, RA.stubUndefined),
R.ifElse(RA.isNumber, n => n + 1, RA.stubUndefined),
R.ifElse(RA.isDate, R.T, RA.stubUndefined),
]);
fnSwitch(1); //=> 2
Parameters:
Name | Type | Description |
---|---|---|
functions |
Array | A list of functions |
Returns:
Returns the first not-nil value, or undefined if either an empty list is provided or none of the dispatching functions returns a non-nil value
- Type
- * | undefined
(static) divideNum(divisor, dividend) → {number}
- Source:
- Since:
- Signature:
-
Number -> Number -> Number
- Category:
-
- Math
Divides two numbers, where the second number is divided by the first number.
Example
RA.divideNum(2, 1); //=> 0.5
Parameters:
Name | Type | Description |
---|---|---|
divisor |
number | the number to divide by |
dividend |
number | the number to divide |
Returns:
A number representing the quotient of dividing the dividend by the divisor
- Type
- number
(static) dropArgs(fn) → {function}
- Source:
- Since:
- Signature:
-
(...a -> b)-> () -> b
- Category:
-
- Logic
- See also:
Accepts a function with any arity and returns a function with arity of zero. The returned function ignores any arguments supplied to it.
Example
const fn = (a = 1, b = 2) => a + b;
RA.dropArgs(fn)('ignore1', 'ignore2'); //=> 3
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | The function with any arity |
Returns:
Returns function with arity of zero
- Type
- function
(static) ensureArray(val) → {Array}
- Source:
- Since:
- Signature:
-
a | [a] -> [a]
- Category:
-
- List
- See also:
Returns a singleton array containing the value provided. If value is already an array, it is returned as is.
Example
RA.ensureArray(42); //=> [42]
RA.ensureArray([42]); //=> [42]
Parameters:
Name | Type | Description |
---|---|---|
val |
* | Array | the value ensure as Array |
Returns:
- Type
- Array
(static) escapeRegExp(val) → {string}
- Source:
- Since:
- Signature:
-
String -> String
- Category:
-
- String
- See also:
Escapes the RegExp special characters.
Example
RA.escapeRegExp('[ramda-adjunct](https://github.com/char0n/ramda-adjunct)'); //=> '\[ramda\-adjunct\]\(https://github\.com/char0n/ramda\-adjunct\)'
Parameters:
Name | Type | Description |
---|---|---|
val |
string | the value to escape |
Returns:
- Type
- string
(static) filterIndexed(pred, list) → {Array}
- Source:
- Since:
- Signature:
-
Filterable f => ((a, Idx, f a) -> Boolean) -> f a -> f a
-
Idx = Number
- Category:
-
- List
- See also:
R.filter function that more closely resembles Array.prototype.filter
.
It takes two new parameters to its callback function: the current index, and the entire list.
filterIndexed
implementation is simple: const filterIndexed = R.addIndex(R.filter);
Example
const isValueGtIndex = (val, idx) => val > idx;
RA.filterIndexed(isValueGtIndex, [5, 4, 3, 2, 1, 0]); //=> [5, 4, 3]
Parameters:
Name | Type | Description |
---|---|---|
pred |
function | The predicate function |
list |
Array | The collection to filter |
Returns:
Filterable
- Type
- Array
(static) findOr(defaultValue, fn, list) → {*}
- Source:
- Since:
- Signature:
-
a -> (b -> Boolean) -> [b] -> b | a
- Category:
-
- List
- See also:
Returns the first element of the list which matches the predicate.
Returns default value if no element matches or matched element is null
, undefined
or NaN
.
Dispatches to the find method of the second argument, if present.
Acts as a transducer if a transformer is given in list position.
Example
RA.findOr(1, isUndefined, [1, 2, undefined]); // => 1
RA.findOr(1, val => val === 2, [1, 2, undefined]); // => 2
RA.findOr(1, val => val === 3, [1, 2, undefined]); // => 1
Parameters:
Name | Type | Description |
---|---|---|
defaultValue |
* | The default value |
fn |
function | The predicate function used to determine if the element is the desired one. |
list |
Array | The array to consider. |
Returns:
The element found, or the default value.
- Type
- *
(static) flattenDepth(depthnon-null, listnon-null) → (non-null) {Array}
- Source:
- Since:
- Signature:
-
Number -> [a] -> [b]
- Category:
-
- List
- See also:
Flattens the list to the specified depth.
Example
RA.flattenDepth(
2,
[1, [2], [3, [4, 5], 6, [[[7], 8]]], 9, 10]
); //=> [1, 2, 3, 4, 5, 6, [[7], 8], 9, 10];
Parameters:
Name | Type | Description |
---|---|---|
depth |
number | The maximum recursion depth |
list |
Array | The array to flatten |
Returns:
Returns the new flattened array
- Type
- Array
(static) flattenPath(pathnon-null, objnon-null) → (non-null) {Object}
- Source:
- Since:
- Signature:
-
[Idx] -> {k: v} -> {k: v}
-
Idx = String | Int
- Category:
-
- Object
- See also:
Flattens a property path so that its fields are spread out into the provided object.
It's like spreadPath
, but preserves object under the property path.
Example
RA.flattenPath(
['b1', 'b2'],
{ a: 1, b1: { b2: { c: 3, d: 4 } } }
); // => { a: 1, c: 3, d: 4, b1: { b2: { c: 3, d: 4 } } };
Parameters:
Name | Type | Description |
---|---|---|
path |
Array.<(string|number)> | The property path to flatten |
obj |
Object | The provided object |
Returns:
The flattened object
- Type
- Object
(static) flattenProp(prop, objnon-null) → (non-null) {Object}
- Source:
- Since:
- Signature:
-
[Idx] -> {k: v} -> {k: v}
-
Idx = String | Int
- Category:
-
- Object
- See also:
Flattens a property so that its fields are spread out into the provided object.
It's like spreadProp
, but preserves object under the property path.
Example
RA.flattenProp(
'b',
{ a: 1, b: { c: 3, d: 4 } }
); // => { a: 1, c: 3, d: 4, b: { c: 3, d: 4 } };
Parameters:
Name | Type | Description |
---|---|---|
prop |
string | number | The property to flatten |
obj |
Object | The provided object |
Returns:
The flattened object
- Type
- Object
(static) floor(number) → {number}
Returns the largest integer less than or equal to a given number.
Note: floor(null) returns integer 0 and do not give a NaN error.
Example
RA.floor(45.95); //=> 45
RA.floor(45.05); //=> 45
RA.floor(4); //=> 4
RA.floor(-45.05); //=> -46
RA.floor(-45.95); //=> -46
RA.floor(null); //=> 0
Parameters:
Name | Type | Description |
---|---|---|
number |
number | The number to floor |
Returns:
A number representing the largest integer less than or equal to the specified number
- Type
- number
(static) fnull(function, defaults) → {function}
Returns a function which is called with the given arguments. If any of the given arguments are null or undefined, the corresponding default value for that argument is used instead.
Example
const addDefaults = RA.fnull((a, b) => a + b, [4, 5])
addDefaults(1, 2); // => 3
addDefaults(null, 2); // => 6
addDefaults(2, null); // => 7
addDefaults(undefined, undefined); // => 9
Parameters:
Name | Type | Description |
---|---|---|
function |
function | to be executed |
defaults |
Array | default arguments |
Returns:
will apply provided arguments or default ones
- Type
- function
(static) hasPath(path, obj) → {boolean}
- Source:
- Since:
- Deprecated:
- since v2.12.0; ramda@0.26.0 contains hasPath
- Signature:
-
[Idx] -> {a} -> Boolean
-
Idx = String | Int
- Category:
-
- Object
- See also:
Returns whether or not an object has an own property with the specified name at a given path.
Example
RA.hasPath(['a', 'b'], { a: { b: 1 } }); //=> true
RA.hasPath(['a', 'b', 'c'], { a: { b: 1 } }); //=> false
RA.hasPath(['a', 'b'], { a: { } }); //=> false
RA.hasPath([0], [1, 2]); //=> true
Parameters:
Name | Type | Description |
---|---|---|
path |
Array.<(string|number)> | The path of the nested property |
obj |
Object | The object to test |
Returns:
- Type
- boolean
(static) inRange(low, high, value) → {boolean}
- Source:
- Since:
- Signature:
-
Number -> Number -> Number -> Boolean
- Category:
-
- Relation
Checks if value
is between low
and up to but not including high
.
Example
RA.inRange(0, 5, 3); //=> true
RA.inRange(0, 5, 0); //=> true
RA.inRange(0, 5, 4); //=> true
RA.inRange(0, 5, 5); //=> false
RA.inRange(0, 5, -1); //=> false
Parameters:
Name | Type | Description |
---|---|---|
low |
number | Start of the range |
high |
number | The end of the range |
value |
number | The value to test |
Throws:
-
When
low
is greater than or equal tohigh
- Type
- Error
Returns:
- Type
- boolean
(static) invoke(path, obj) → {*}
Invokes the method at path of object.
Example
RA.invoke(['random'], Math); //=> 0.5113253820009047
Parameters:
Name | Type | Description |
---|---|---|
path |
Array.<(string|number)> | The path of the method to invoke |
obj |
Object | The object to query |
Returns:
- Type
- *
(static) invokeArgs(path, args, obj) → {*}
- Source:
- Since:
- Signature:
-
Array -> Array -> Object -> *
- Category:
-
- Object
Invokes the method at path of object with given arguments.
Example
RA.invokeArgs(['abs'], [-1], Math); //=> 1
RA.invokeArgs(['path', 'to', 'non-existent', 'method'], [-1], Math); //=> undefined
Parameters:
Name | Type | Description |
---|---|---|
path |
Array.<(string|number)> | The path of the method to invoke |
args |
Array | The arguments to invoke the method with |
obj |
Object | The object to query |
Returns:
- Type
- *
(static) isArray(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is Array
.
Example
RA.isArray([]); //=> true
RA.isArray(null); //=> false
RA.isArray({}); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isArrayLike(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Tests whether or not an object is similar to an array.
Example
RA.isArrayLike([]); //=> true
RA.isArrayLike(true); //=> false
RA.isArrayLike({}); //=> false
RA.isArrayLike({length: 10}); //=> false
RA.isArrayLike({0: 'zero', 9: 'nine', length: 10}); //=> true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
true
if val
has a numeric length property and extreme indices defined; false
otherwise.
- Type
- boolean
(static) isAsyncFunction(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is Async Function
.
Example
RA.isAsyncFunction(async function test() { }); //=> true
RA.isAsyncFunction(null); //=> false
RA.isAsyncFunction(function test() { }); //=> false
RA.isAsyncFunction(() => {}); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isBigInt(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
Checks if value is a BigInt.
Example
RA.isBigInt(5); // => false
RA.isBigInt(Number.MAX_VALUE); // => false
RA.isBigInt(-Infinity); // => false
RA.isBigInt(10); // => false
RA.isBigInt(10n); // => true
RA.isBigInt(BitInt(9007199254740991)); // => true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isBoolean(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is Boolean
.
Example
RA.isBoolean(false); //=> true
RA.isBoolean(true); //=> true
RA.isBoolean(null); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isDate(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if value is Date
object.
Example
RA.isDate(new Date()); //=> true
RA.isDate('1997-07-16T19:20+01:00'); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isEmptyArray(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
-
isNotEmptyArray
Checks if input value is an empty Array
.
Example
RA.isEmptyArray([]); // => true
RA.isEmptyArray([42]); // => false
RA.isEmptyArray({}); // => false
RA.isEmptyArray(null); // => false
RA.isEmptyArray(undefined); // => false
RA.isEmptyArray(42); // => false
RA.isEmptyArray('42'); // => false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isEmptyString(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
-
isNotEmptyString
Checks if input value is an empty String
.
Example
RA.isEmptyString(''); // => true
RA.isEmptyString('42'); // => false
RA.isEmptyString(new String('42')); // => false
RA.isEmptyString(new String('')); // => false
RA.isEmptyString([42]); // => false
RA.isEmptyString({}); // => false
RA.isEmptyString(null); // => false
RA.isEmptyString(undefined); // => false
RA.isEmptyString(42); // => false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isError(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
Checks if value
is an Error
, EvalError
, RangeError
, ReferenceError
, SyntaxError
, TypeError
or URIError
object.
Example
RA.isError(new Error()); //=> true
RA.isError(Error); //=> false
RA.isError(1); // => false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
Returns true
if value is an error object, false
otherwise
- Type
- boolean
(static) isEven(val) → {boolean}
Checks if value is even integer number. An even number is an integer which is "evenly divisible" by two. Zero is an even number because zero divided by two equals zero, which despite not being a natural number, is an integer. Even numbers are either positive or negative.
Example
RA.isEven(0); // => true
RA.isEven(1); // => false
RA.isEven(-Infinity); // => false
RA.isEven(4); // => true
RA.isEven(3); // => false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isFalse(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is the Boolean primitive false
. Will return false for all values created
using the Boolean
function as a constructor.
Example
RA.isFalse(false); // => true
RA.isFalse(Boolean(false)); // => true
RA.isFalse(true); // => false
RA.isFalse(0); // => false
RA.isFalse(''); // => false
RA.isFalse(null); // => false
RA.isFalse(undefined); // => false
RA.isFalse(NaN); // => false
RA.isFalse([]); // => false
RA.isFalse(new Boolean(false)); // => false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isFalsy(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
A falsy value is a value that translates to false when evaluated in a Boolean context.
Falsy values are false
, 0
, ""
, null
, undefined
, and NaN
.
Example
RA.isFalsy(false); // => true
RA.isFalsy(0); // => true
RA.isFalsy(''); // => true
RA.isFalsy(null); // => true
RA.isFalsy(undefined); // => true
RA.isFalsy(NaN); // => true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isFinite(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks whether the passed value is a finite Number
.
Example
RA.isFinite(Infinity); //=> false
RA.isFinite(NaN); //=> false
RA.isFinite(-Infinity); //=> false
RA.isFinite(0); // true
RA.isFinite(2e64); // true
RA.isFinite('0'); // => false
// would've been true with global isFinite('0')
RA.isFinite(null); // => false
// would've been true with global isFinite(null)
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isFloat(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks whether the passed value is a float
.
Example
RA.isFloat(0); //=> false
RA.isFloat(1); //=> false
RA.isFloat(-100000); //=> false
RA.isFloat(0.1); //=> true
RA.isFloat(Math.PI); //=> true
RA.isFloat(NaN); //=> false
RA.isFloat(Infinity); //=> false
RA.isFloat(-Infinity); //=> false
RA.isFloat('10'); //=> false
RA.isFloat(true); //=> false
RA.isFloat(false); //=> false
RA.isFloat([1]); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isFunction(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is Function
.
Example
RA.isFunction(function test() { }); //=> true
RA.isFunction(function* test() { }); //=> true
RA.isFunction(async function test() { }); //=> true
RA.isFunction(() => {}); //=> true
RA.isFunction(null); //=> false
RA.isFunction('abc'); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isGeneratorFunction(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is Generator Function
.
Example
RA.isGeneratorFunction(function* test() { }); //=> true
RA.isGeneratorFunction(null); //=> false
RA.isGeneratorFunction(function test() { }); //=> false
RA.isGeneratorFunction(() => {}); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isIndexed(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
Determine if input value is an indexed data type.
Example
RA.isIndexed([1]) //=> true
RA.isIndexed('test') //=> true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isInteger(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks whether the passed value is an integer
.
Example
RA.isInteger(0); //=> true
RA.isInteger(1); //=> true
RA.isInteger(-100000); //=> true
RA.isInteger(0.1); //=> false
RA.isInteger(Math.PI); //=> false
RA.isInteger(NaN); //=> false
RA.isInteger(Infinity); //=> false
RA.isInteger(-Infinity); //=> false
RA.isInteger('10'); //=> false
RA.isInteger(true); //=> false
RA.isInteger(false); //=> false
RA.isInteger([1]); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isInteger32(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Aliases:
-
- isInt32
- Category:
-
- Type
- See also:
Checks whether the passed value is a signed 32 bit integer.
Example
RA.isInteger32(0); //=> true
RA.isInteger32((-2) ** 31); //=> true
RA.isInteger32(Infinity); //=> false
RA.isInteger32(NaN); //=> false
RA.isInteger32(2 ** 31); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isIterable(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks whether the passed value is iterable.
Example
RA.isIterable(['arrays', 'are', 'iterable']); //=> true
RA.isIterable('strings are iterable, too'); //=> true
RA.isIterable((function* () {})()); //=> true (generator objects are both iterable and iterators)
RA.isIterable({}); //=> false
RA.isIterable(-0); //=> false
RA.isIterable(null); //=> false
RA.isIterable(undefined); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isMap(val) → {boolean}
Predicate for determining if a provided value is an instance of a Map.
Example
RA.isMap(new Map()); //=> true
RA.isMap(new Map([[1, 2], [2, 1]])); //=> true
RA.isSet(new Set()); //=> false
RA.isSet(new Set([1,2]); //=> false
RA.isSet(new Object()); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNaN(val) → {boolean}
Checks whether the passed value is NaN
and its type is Number
.
It is a more robust version of the original, global isNaN().
Example
RA.isNaN(NaN); // => true
RA.isNaN(Number.NaN); // => true
RA.isNaN(0 / 0); // => true
// e.g. these would have been true with global isNaN().
RA.isNaN('NaN'); // => false
RA.isNaN(undefined); // => false
RA.isNaN({}); // => false
RA.isNaN('blabla'); // => false
RA.isNaN(true); // => false
RA.isNaN(null); // => false
RA.isNaN(37); // => false
RA.isNaN('37'); // => false
RA.isNaN('37.37'); // => false
RA.isNaN(''); // => false
RA.isNaN(' '); // => false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNaturalNumber(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
Checks if value is a natural number. Natural numbers correspond to all non-negative integers and 0.
Example
RA.isNaturalNumber(5); // => true
RA.isNaturalNumber(Number.MAX_VALUE); // => true
RA.isNaturalNumber(0); // => true
RA.isNaturalNumber(-1); // => false
RA.isNaturalNumber(0.9); // => false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNegative(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if value is a negative Number
primitive or object. Zero is not considered neither
positive or negative.
Example
RA.isNegative(-1); // => true
RA.isNegative(Number.MIN_VALUE); // => false
RA.isNegative(+Infinity); // => false
RA.isNegative(NaN); // => false
RA.isNegative('5'); // => false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNegativeZero(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
-
- @see
isPositiveZero
- @see
Checks if value is a negative zero (-0).
Example
RA.isNegativeZero(-0); //=> true
RA.isNegativeZero(+0); //=> false
RA.isNegativeZero(0); //=> false
RA.isNegativeZero(null); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNilOrEmpty(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Returns true
if the given value is its type's empty value, null
or undefined
.
Example
RA.isNilOrEmpty([1, 2, 3]); //=> false
RA.isNilOrEmpty([]); //=> true
RA.isNilOrEmpty(''); //=> true
RA.isNilOrEmpty(null); //=> true
RA.isNilOrEmpty(undefined): //=> true
RA.isNilOrEmpty({}); //=> true
RA.isNilOrEmpty({length: 0}); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNonEmptyArray(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is not an empty Array
.
Example
RA.isNonEmptyArray([42]); // => true
RA.isNonEmptyArray([]); // => false
RA.isNonEmptyArray({}); // => false
RA.isNonEmptyArray(null); // => false
RA.isNonEmptyArray(undefined); // => false
RA.isNonEmptyArray(42); // => false
RA.isNonEmptyArray('42'); // => false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNonEmptyString(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is not an empty String
.
Example
RA.isNonEmptyString('42'); // => true
RA.isNonEmptyString(''); // => false
RA.isNonEmptyString(new String('42')); // => false
RA.isNonEmptyString(new String('')); // => false
RA.isNonEmptyString([42]); // => false
RA.isNonEmptyString({}); // => false
RA.isNonEmptyString(null); // => false
RA.isNonEmptyString(undefined); // => false
RA.isNonEmptyString(42); // => false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNonNegative(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if value is a non-negative Number
primitive or object. This includes all positive
numbers and zero.
Example
RA.isNonNegative(0); // => true
RA.isNonNegative(1); // => true
RA.isNonNegative(Infinity); // => true
RA.isNonNegative(Number.MAX_VALUE); // => true
RA.isNonNegative(-Infinity); // => false
RA.isNonNegative(Number.MIN_VALUE); // => false
RA.isNonNegative(NaN); // => false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNonPositive(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if value is a non-positive Number
primitive or object. This includes all negative
numbers and zero.
Example
RA.isNonPositive(0); // => true
RA.isNonPositive(-1); // => true
RA.isNonPositive(-Infinity); // => true
RA.isNonPositive(Number.MIN_VALUE); // => true
RA.isNonPositive(Infinity); // => false
RA.isNonPositive(Number.MAX_VALUE); // => false
RA.isNonPositive(NaN); // => false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotArray(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is complement of Array
Example
RA.isNotArray([]); //=> false
RA.isNotArray(null); //=> true
RA.isNotArray({}); //=> true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotArrayLike(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Tests whether or not an object is similar to an array.
Example
RA.isNotArrayLike([]); //=> false
RA.isNotArrayLike(true); //=> true
RA.isNotArrayLike({}); //=> true
RA.isNotArrayLike({length: 10}); //=> true
RA.isNotArrayLike({0: 'zero', 9: 'nine', length: 10}); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotAsyncFunction(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is complement of Async Function
Example
RA.isNotAsyncFunction(async function test() { }); //=> false
RA.isNotAsyncFunction(null); //=> true
RA.isNotAsyncFunction(function test() { }); //=> true
RA.isNotAsyncFunction(() => {}); //=> true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotBoolean(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is complement of Boolean
.
Example
RA.isNotBoolean(false); //=> false
RA.isNotBoolean(true); //=> false
RA.isNotBoolean(null); //=> true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotDate(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if value is complement of Date
object.
Example
RA.isNotDate(new Date()); //=> false
RA.isNotDate('1997-07-16T19:20+01:00'); //=> true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotEmpty(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Logic
- See also:
Returns true if the given value is not its type's empty value; false
otherwise.
Example
RA.isNotEmpty([1, 2, 3]); //=> true
RA.isNotEmpty([]); //=> false
RA.isNotEmpty(''); //=> false
RA.isNotEmpty(null); //=> true
RA.isNotEmpty(undefined): //=> true
RA.isNotEmpty({}); //=> false
RA.isNotEmpty({length: 0}); //=> true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotFinite(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks whether the passed value is complement of finite Number
.
Example
RA.isNotFinite(Infinity); //=> true
RA.isNotFinite(NaN); //=> true
RA.isNotFinite(-Infinity); //=> true
RA.isNotFinite(0); // false
RA.isNotFinite(2e64); // false
RA.isNotFinite('0'); // => true
RA.isNotFinite(null); // => true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotFloat(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks whether the passed value is complement of a float
.
Example
RA.isNotFloat(0); //=> true
RA.isNotFloat(1); //=> true
RA.isNotFloat(-100000); //=> true
RA.isNotFloat(0.1); //=> false
RA.isNotFloat(Math.PI); //=> false
RA.isNotFloat(NaN); //=> true
RA.isNotFloat(Infinity); //=> true
RA.isNotFloat(-Infinity); //=> true
RA.isNotFloat('10'); //=> true
RA.isNotFloat(true); //=> true
RA.isNotFloat(false); //=> true
RA.isNotFloat([1]); //=> true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotFunction(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is complement of Function
.
Example
RA.isNotFunction(function test() { }); //=> false
RA.isNotFunction(function* test() { }); //=> false
RA.isNotFunction(async function test() { }); //=> false
RA.isNotFunction(() => {}); //=> false
RA.isNotFunction(null); //=> true
RA.isNotFunction('abc'); //=> true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotGeneratorFunction(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is complement of Generator Function
Example
RA.isNotGeneratorFunction(function* test() { }); //=> false
RA.isNotGeneratorFunction(null); //=> true
RA.isNotGeneratorFunction(function test() { }); //=> true
RA.isNotGeneratorFunction(() => {}); //=> true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotInteger(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks whether the passed value is complement of an integer
.
Example
RA.isNotInteger(0); //=> false
RA.isNotInteger(1); //=> false
RA.isNotInteger(-100000); //=> false
RA.isNotInteger(0.1); //=> true
RA.isNotInteger(Math.PI); //=> true
RA.isNotInteger(NaN); //=> true
RA.isNotInteger(Infinity); //=> true
RA.isNotInteger(-Infinity); //=> true
RA.isNotInteger('10'); //=> true
RA.isNotInteger(true); //=> true
RA.isNotInteger(false); //=> true
RA.isNotInteger([1]); //=> true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotMap(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if value is complement of Map
object.
Example
RA.isNotMap(new Map()); //=> false
RA.isNotMap(new Map([[1, 2], [2, 1]])); //=> false
RA.isNotMap(new Set()); //=> true
RA.isNotMap({}); //=> true
RA.isNotMap(12); //=> true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotNaN(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks whether the passed value is complement of NaN
and its type is not Number
.
Example
RA.isNotNaN(NaN); // => false
RA.isNotNaN(Number.NaN); // => false
RA.isNotNaN(0 / 0); // => false
RA.isNotNaN('NaN'); // => true
RA.isNotNaN(undefined); // => true
RA.isNotNaN({}); // => true
RA.isNotNaN('blabla'); // => true
RA.isNotNaN(true); // => true
RA.isNotNaN(null); // => true
RA.isNotNaN(37); // => true
RA.isNotNaN('37'); // => true
RA.isNotNaN('37.37'); // => true
RA.isNotNaN(''); // => true
RA.isNotNaN(' '); // => true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotNil(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is complement of null
or undefined
.
Example
RA.isNotNil(null); //=> false
RA.isNotNil(undefined); //=> false
RA.isNotNil(0); //=> true
RA.isNotNil([]); //=> true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotNilOrEmpty(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Returns false
if the given value is its type's empty value, null
or undefined
.
Example
RA.isNotNilOrEmpty([1, 2, 3]); //=> true
RA.isNotNilOrEmpty([]); //=> false
RA.isNotNilOrEmpty(''); //=> false
RA.isNotNilOrEmpty(null); //=> false
RA.isNotNilOrEmpty(undefined): //=> false
RA.isNotNilOrEmpty({}); //=> false
RA.isNotNilOrEmpty({length: 0}); //=> true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotNull(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is complement of null
.
Example
RA.isNotNull(1); //=> true
RA.isNotNull(undefined); //=> true
RA.isNotNull(null); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotNumber(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if value is a complement of Number
primitive or object.
Example
RA.isNotNumber(5); // => false
RA.isNotNumber(Number.MAX_VALUE); // => false
RA.isNotNumber(-Infinity); // => false
RA.isNotNumber('5'); // => true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotObj(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Aliases:
-
- isNotObject
- Category:
-
- Type
- See also:
Checks if input value is complement of language type of Object
.
Example
RA.isNotObj({}); //=> false
RA.isNotObj([]); //=> false
RA.isNotObj(() => {}); //=> false
RA.isNotObj(null); //=> true
RA.isNotObj(undefined); //=> true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotObjLike(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Aliases:
-
- isNotObjectLike
- Category:
-
- Type
- See also:
Checks if value is not object-like. A value is object-like if it's not null and has a typeof result of "object".
Example
RA.isNotObjLike({}); //=> false
RA.isNotObjLike([]); //=> false
RA.isNotObjLike(() => {}); //=> true
RA.isNotObjLike(null); //=> true
RA.isNotObjLike(undefined); //=> true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotPair(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is complement of a pair.
Example
RA.isNotPair([]); // => true
RA.isNotPair([0]); // => true
RA.isNotPair([0, 1]); // => false
RA.isNotPair([0, 1, 2]); // => true
RA.isNotPair({0: 0, 1: 1}); // => true
RA.isNotPair({foo: 0, bar: 0}); // => true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotPlainObj(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Aliases:
-
- isNotPlainObject
- Category:
-
- Type
- See also:
Check to see if an object is a not plain object (created using {}
, new Object()
or Object.create(null)
).
Example
class Bar {
constructor() {
this.prop = 'value';
}
}
RA.isNotPlainObj(new Bar()); //=> true
RA.isNotPlainObj({ prop: 'value' }); //=> false
RA.isNotPlainObj(['a', 'b', 'c']); //=> true
RA.isNotPlainObj(Object.create(null); //=> false
RA.isNotPlainObj(new Object()); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotRegExp(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if value is complement of RegExp
object.
Example
RA.isNotRegExp(1); //=> true
RA.isNotRegExp(/(?:)/); //=> false
RA.isNotRegExp(new RegExp()); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotSet(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if value is complement of Set
object.
Example
RA.isNotSet(new Map()); //=> true
RA.isNotSet(new Set()); //=> false
RA.isNotSet(new Set([1,2]); //=> false
RA.isNotSet(new Object()); //=> true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotString(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is complement of String
.
Example
RA.isNotString('abc'); //=> false
RA.isNotString(1); //=> true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotUndefined(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is complement undefined
.
Example
RA.isNotUndefined(1); //=> true
RA.isNotUndefined(undefined); //=> false
RA.isNotUndefined(null); //=> true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotValidDate(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Aliases:
-
- isInvalidDate
- Category:
-
- Type
- See also:
Checks if value is complement of valid Date
object.
Example
RA.isNotValidDate(new Date()); //=> false
RA.isNotValidDate(new Date('a')); //=> true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNotValidNumber(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if value is not a valid Number
. A valid Number
is a number that is not NaN
,
Infinity
or -Infinity
.
Example
RA.isNotValidNumber(1); //=> false
RA.isNotValidNumber(''); //=> true
RA.isNotValidNumber(NaN); //=> true
RA.isNotValidNumber(Infinity); //=> true
RA.isNotValidNumber(-Infinity); //=> true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNull(val) → {boolean}
Checks if input value is null
.
Example
RA.isNull(1); //=> false
RA.isNull(undefined); //=> false
RA.isNull(null); //=> true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isNumber(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if value is a Number
primitive or object.
Example
RA.isNumber(5); // => true
RA.isNumber(Number.MAX_VALUE); // => true
RA.isNumber(-Infinity); // => true
RA.isNumber(NaN); // => true
RA.isNumber('5'); // => false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isObj(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Aliases:
-
- isObject
- Category:
-
- Type
- See also:
Checks if input value is language type of Object
.
Example
RA.isObj({}); //=> true
RA.isObj([]); //=> true
RA.isObj(() => {}); //=> true
RA.isObj(null); //=> false
RA.isObj(undefined); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isObjLike(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Aliases:
-
- isObjectLike
- Category:
-
- Type
- See also:
Checks if value is object-like. A value is object-like if it's not null and has a typeof result of "object".
Example
RA.isObjLike({}); //=> true
RA.isObjLike([]); //=> true
RA.isObjLike(() => {}); //=> false
RA.isObjLike(null); //=> false
RA.isObjLike(undefined); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isOdd(val) → {boolean}
Checks if value is odd integer number. An odd number is an integer which is not a multiple DIVISIBLE of two.
Example
RA.isOdd(1); // => true
RA.isOdd(-Infinity); // => false
RA.isOdd(4); // => false
RA.isOdd(3); // => true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isPair(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is a pair.
Example
RA.isPair([]); // => false
RA.isPair([0]); // => false
RA.isPair([0, 1]); // => true
RA.isPair([0, 1, 2]); // => false
RA.isPair({ 0: 0, 1: 1 }); // => false
RA.isPair({ foo: 0, bar: 0 }); // => false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isPlainObj(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Aliases:
-
- isPlainObject
- Category:
-
- Type
- See also:
Check to see if an object is a plain object (created using {}
, new Object()
or Object.create(null)
).
Example
class Bar {
constructor() {
this.prop = 'value';
}
}
RA.isPlainObj(new Bar()); //=> false
RA.isPlainObj({ prop: 'value' }); //=> true
RA.isPlainObj(['a', 'b', 'c']); //=> false
RA.isPlainObj(Object.create(null); //=> true
RA.isPlainObj(new Object()); //=> true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isPositive(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if value is a positive Number
primitive or object. Zero is not considered positive.
Example
RA.isPositive(1); // => true
RA.isPositive(Number.MAX_VALUE); // => true
RA.isPositive(-Infinity); // => false
RA.isPositive(NaN); // => false
RA.isPositive('5'); // => false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isPositiveZero(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if value is a positive zero (+0).
Example
RA.isPositiveZero(+0); //=> true
RA.isPositiveZero(0); //=> true
RA.isPositiveZero(-0); //=> false
RA.isPositiveZero(null); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isPromise(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is a native Promise
.
The Promise object represents the eventual completion (or failure)
of an asynchronous operation, and its resulting value.
Example
RA.isPromise(null); // => false
RA.isPromise(undefined); // => false
RA.isPromise([]); // => false
RA.isPromise(Promise.resolve()); // => true
RA.isPromise(Promise.reject()); // => true
RA.isPromise({ then: () => 1 }); // => false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isPrototypeOf(type, object) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Object
- See also:
Checks if an object exists in another object's prototype chain.
Example
function Foo() {}
function Bar() {}
function Baz() {}
Bar.prototype = Object.create(Foo.prototype);
Baz.prototype = Object.create(Bar.prototype);
const baz = new Baz();
RA.isPrototypeOf(Baz, baz); // => true
RA.isPrototypeOf(Bar, baz); // => true
RA.isPrototypeOf(Foo, baz); // => true
RA.isPrototypeOf(Object, baz); // => true
Parameters:
Name | Type | Description |
---|---|---|
type |
Object | The prototype that we're searching for |
object |
Object | The object whose prototype chain will be searched |
Returns:
- Type
- boolean
(static) isRegExp(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if value is RegExp
object.
Example
RA.isRegExp(new RegExp()); //=> true
RA.isRegExp(/(?:)/); //=> true
RA.isRegExp(1); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isSafeInteger(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
Checks whether the passed value is a safe integer
.
Example
RA.isSafeInteger(3); //=> true
RA.isSafeInteger(Math.pow(2, 53)) //=> false
RA.isSafeInteger(Math.pow(2, 53) - 1); //=> true
RA.isSafeInteger(NaN); //=> false
RA.isSafeInteger(Infinity); //=> false
RA.isSafeInteger('3') //=> false
RA.isSafeInteger(3.1); //=> false
RA.isSafeInteger(3.0); //=> true
RA.isSafeInteger('string'); //=> false
RA.isSafeInteger(null); //=> false
RA.isSafeInteger(undefined); //=> false
RA.isSafeInteger({}); //=> false
RA.isSafeInteger(() => { }); //=> false
RA.isSafeInteger(true); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isSentinelValue(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
Checks whether the passed value is a sentinel value.
Example
RA.isSentinelValue(-1); //=> true
RA.isSentinelValue('-1'); //=> false
RA.isSentinelValue(1); //=> false
RA.isSentinelValue([-1]); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isSet(val) → {boolean}
Predicate for determining if a provided value is an instance of a Set.
Example
RA.isSet(new Map()); //=> false
RA.isSet(new Set()); //=> true
RA.isSet(new Set([1,2]); //=> true
RA.isSet(new Object()); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isSparseArray(list) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is a sparse Array.
An array with at least one "empty slot" in it is often called a "sparse array."
Empty slot doesn't mean that the slot contains null
or undefined
values,
but rather that the slots don't exist.
Example
RA.isSparseArray(new Array(3)); // => true
RA.isSparseArray([1,,3]); // => true
const list = [1, 2, 3];
delete list[1];
RA.isSparseArray(list); // => true
RA.isSparseArray([1, 2, 3]); // => false
Parameters:
Name | Type | Description |
---|---|---|
list |
* | The list to test |
Returns:
- Type
- boolean
(static) isString(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is String
.
Example
RA.isString('abc'); //=> true
RA.isString(1); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isSymbol(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is a Symbol.
Example
RA.isSymbol(Symbol('1')); //=> true
RA.isSymbol(Symbol(1)); //=> true
RA.isSymbol('string'); //=> false
RA.isSymbol(undefined); //=> false
RA.isSymbol(null); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isThenable(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is a thenable
.
thenable
is an object or function that defines a then
method.
Example
RA.isThenable(null); // => false
RA.isThenable(undefined); // => false
RA.isThenable([]); // => false
RA.isThenable(Promise.resolve()); // => true
RA.isThenable(Promise.reject()); // => true
RA.isThenable({ then: () => 1 }); // => true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isTrue(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is the Boolean primitive true
. Will return false for Boolean objects
created using the Boolean
function as a constructor.
Example
RA.isTrue(true); // => true
RA.isTrue(Boolean(true)); // => true
RA.isTrue(false); // => false
RA.isTrue(1); // => false
RA.isTrue('true'); // => false
RA.isTrue(new Boolean(true)); // => false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isTruthy(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
In JavaScript, a truthy
value is a value that is considered true
when evaluated in a Boolean context. All values are truthy unless
they are defined as falsy (i.e., except for false
, 0
, ""
, null
, undefined
, and NaN
).
Example
RA.isTruthy({}); // => true
RA.isTruthy([]); // => true
RA.isTruthy(42); // => true
RA.isTruthy(3.14); // => true
RA.isTruthy('foo'); // => true
RA.isTruthy(new Date()); // => true
RA.isTruthy(Infinity); // => true
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isUndefined(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if input value is undefined
.
Example
RA.isUndefined(1); //=> false
RA.isUndefined(undefined); //=> true
RA.isUndefined(null); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isValidDate(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if value is valid Date
object.
Example
RA.isValidDate(new Date()); //=> true
RA.isValidDate(new Date('a')); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) isValidNumber(val) → {boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if value is a valid Number
. A valid Number
is a number that is not NaN
, Infinity
or -Infinity
.
Example
RA.isValidNumber(1); //=> true
RA.isValidNumber(''); //=> false
RA.isValidNumber(NaN); //=> false
RA.isValidNumber(Infinity); //=> false
RA.isValidNumber(-Infinity); //=> false
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to test |
Returns:
- Type
- boolean
(static) lastP(iterable) → {Promise}
- Source:
- Since:
- Signature:
-
[Promise a] -> Promise a
- Category:
-
- Function
- See also:
Returns a promise that is fulfilled by the last given promise to be fulfilled, or rejected with an array of rejection reasons if all of the given promises are rejected.
Example
const delayP = timeout => new Promise(resolve => setTimeout(() => resolve(timeout), timeout));
delayP.reject = timeout => new Promise((resolve, reject) => setTimeout(() => reject(timeout), timeout));
RA.lastP([
1,
delayP(10),
delayP(100),
delayP.reject(1000),
]); //=> Promise(100)
Parameters:
Name | Type | Description |
---|---|---|
iterable |
Iterable.<*> | An iterable object such as an Array or String |
Returns:
A promise that is fulfilled by the last given promise to be fulfilled, or rejected with an array of rejection reasons if all of the given promises are rejected.
- Type
- Promise
(static) lengthEq(valueLength, value) → {boolean}
- Source:
- Since:
- Signature:
-
Number -> [*] -> Boolean
- Category:
-
- List
- See also:
Returns true
if the supplied list or string has a length equal to valueLength
.
Example
RA.lengthEq(3, [1,2,3]); //=> true
RA.lengthEq(3, [1,2,3,4]); //=> false
Parameters:
Name | Type | Description |
---|---|---|
valueLength |
number | The length of the list or string |
value |
Array | string | The list or string |
Returns:
- Type
- boolean
(static) lengthGt(valueLength, value) → {boolean}
- Source:
- Since:
- Signature:
-
Number -> [*] -> Boolean
- Category:
-
- List
- See also:
Returns true
if the supplied list or string has a length greater than valueLength
.
Example
RA.lengthGt(3, [1,2,3,4]); //=> true
RA.lengthGt(3, [1,2,3]); //=> false
Parameters:
Name | Type | Description |
---|---|---|
valueLength |
number | The length of the list or string |
value |
Array | string | The list or string |
Returns:
- Type
- boolean
(static) lengthGte(valueLength, value) → {boolean}
- Source:
- Since:
- Signature:
-
Number -> [*] -> Boolean
- Category:
-
- List
- See also:
Returns true
if the supplied list or string has a length greater than or equal to
valueLength
.
Example
RA.lengthGte(3, [1,2,3,4]); //=> true
RA.lengthGte(3, [1,2,3]); //=> true
RA.lengthGte(3, [1,2]); //=> false
Parameters:
Name | Type | Description |
---|---|---|
valueLength |
number | The length of the list or string |
value |
Array | string | The list or string |
Returns:
- Type
- boolean
(static) lengthLt(valueLength, value) → {boolean}
- Source:
- Since:
- Signature:
-
Number -> [*] -> Boolean
- Category:
-
- List
- See also:
Returns true
if the supplied list or string has a length less than valueLength
.
Example
RA.lengthLt(3, [1,2]); //=> true
RA.lengthLt(3, [1,2,3]); //=> false
Parameters:
Name | Type | Description |
---|---|---|
valueLength |
number | The length of the list or string |
value |
Array | string | The list or string |
Returns:
- Type
- boolean
(static) lengthLte(valueLength, value) → {boolean}
- Source:
- Since:
- Signature:
-
Number -> [*] -> Boolean
- Category:
-
- List
- See also:
Returns true
if the supplied list or string has a length less than or equal to valueLength
.
Example
RA.lengthLte(3, [1,2]); //=> true
RA.lengthLte(3, [1,2,3]); //=> true
RA.lengthLte(3, [1,2,3,4]); //=> false
Parameters:
Name | Type | Description |
---|---|---|
valueLength |
number | The length of the list or string |
value |
Array | string | The list or string |
Returns:
- Type
- boolean
(static) lengthNotEq(valueLength, value) → {boolean}
- Source:
- Since:
- Signature:
-
Number -> [*] -> Boolean
- Category:
-
- List
- See also:
Returns true
if the supplied list or string has a length not equal to valueLength
.
Example
RA.lengthNotEq(3, [1,2,3,4]); //=> true
RA.lengthNotEq(3, [1,2,3]); //=> false
Parameters:
Name | Type | Description |
---|---|---|
valueLength |
number | The length of the list or string |
value |
Array | string | The list or string |
Returns:
- Type
- boolean
(static) lensEq(lens, value, data) → {boolean}
- Source:
- Since:
- Signature:
-
Lens s a -> b -> s -> Boolean
-
Lens s a = Functor f => (a -> f a) -> s -> f s
- Category:
-
- Relation
- See also:
Returns true
if data structure focused by the given lens equals provided value.
Example
RA.lensEq(R.lensIndex(0), 1, [0, 1, 2]); // => false
RA.lensEq(R.lensIndex(1), 1, [0, 1, 2]); // => true
RA.lensEq(R.lensPath(['a', 'b']), 'foo', { a: { b: 'foo' } }) // => true
Parameters:
Name | Type | Description |
---|---|---|
lens |
function | Van Laarhoven lens |
value |
* | The value to compare the focused data structure with |
data |
* | The data structure |
Returns:
true
if the focused data structure equals value, false
otherwise
- Type
- boolean
(static) lensIso(tonon-null, fromnon-null) → (non-null) {function}
- Source:
- Since:
- Signature:
-
(s -> a) -> (a -> s) -> Lens s a
-
Lens s a = Functor f => (a -> f a) -> s -> f s
- Category:
-
- Relation
- See also:
Defines an isomorphism that will work like a lens. It takes two functions. The function that converts and the function that recovers.
Example
const lensJSON = RA.lensIso(JSON.parse, JSON.stringify);
R.over(lensJSON, assoc('b', 2), '{"a":1}'); //=> '{"a":1,"b":2}'
R.over(RA.lensIso.from(lensJSON), R.replace('}', ',"b":2}'), { a: 1 }); // => { a: 1, b: 2 }
Parameters:
Name | Type | Description |
---|---|---|
to |
function | The function that converts |
from |
function | The function that recovers |
Returns:
The isomorphic lens
- Type
- function
(static) lensNotEq(lens, value, data) → {boolean}
- Source:
- Since:
- Signature:
-
Lens s a -> b -> s -> Boolean
-
Lens s a = Functor f => (a -> f a) -> s -> f s
- Category:
-
- Relation
- See also:
Returns true
if data structure focused by the given lens doesn't equal provided value.
Example
RA.lensNotEq(R.lensIndex(0), 1, [0, 1, 2]); // => true
RA.lensNotEq(R.lensIndex(1), 1, [0, 1, 2]); // => false
RA.lensNotEq(R.lensPath(['a', 'b']), 'foo', { a: { b: 'foo' } }) // => false
Parameters:
Name | Type | Description |
---|---|---|
lens |
function | Van Laarhoven lens |
value |
* | The value to compare the focused data structure with |
data |
* | The data structure |
Returns:
false
if the focused data structure equals value, true
otherwise
- Type
- boolean
(static) lensNotSatisfy(predicate, lens, data) → {boolean}
- Source:
- Since:
- Signature:
-
Boolean b => (a -> b) -> Lens s a -> s -> b
-
Lens s a = Functor f => (a -> f a) -> s -> f s
- Category:
-
- Relation
- See also:
Returns true
if data structure focused by the given lens doesn't satisfy the predicate.
Note that the predicate is expected to return boolean value.
Example
RA.lensNotSatisfy(RA.isTrue, R.lensIndex(0), [false, true, 1]); // => true
RA.lensNotSatisfy(RA.isTrue, R.lensIndex(1), [false, true, 1]); // => false
RA.lensNotSatisfy(RA.isTrue, R.lensIndex(2), [false, true, 1]); // => true
RA.lensNotSatisfy(R.identity, R.lensProp('x'), { x: 1 }); // => true
Parameters:
Name | Type | Description |
---|---|---|
predicate |
function | The predicate function |
lens |
function | Van Laarhoven lens |
data |
* | The data structure |
Returns:
false
if the focused data structure satisfies the predicate, true
otherwise
- Type
- boolean
(static) lensSatisfies(predicate, lens, data) → {boolean}
- Source:
- Since:
- Signature:
-
Boolean b => (a -> b) -> Lens s a -> s -> b
-
Lens s a = Functor f => (a -> f a) -> s -> f s
- Category:
-
- Relation
- See also:
Returns true
if data structure focused by the given lens satisfies the predicate.
Note that the predicate is expected to return boolean value and will be evaluated
as false
unless the predicate returns true
.
Example
RA.lensSatisfies(RA.isTrue, R.lensIndex(0), [false, true, 1]); // => false
RA.lensSatisfies(RA.isTrue, R.lensIndex(1), [false, true, 1]); // => true
RA.lensSatisfies(RA.isTrue, R.lensIndex(2), [false, true, 1]); // => false
RA.lensSatisfies(R.identity, R.lensProp('x'), { x: 1 }); // => false
Parameters:
Name | Type | Description |
---|---|---|
predicate |
function | The predicate function |
lens |
function | Van Laarhoven lens |
data |
* | The data structure |
Returns:
true
if the focused data structure satisfies the predicate, false
otherwise
- Type
- boolean
(static) lensTraverse(ofnon-null) → (non-null) {function}
- Source:
- Since:
- Signature:
-
Applicative f => (a -> f a) -> Lens s a
-
Lens s a = Functor f => (a -> f a) -> s -> f s
- Category:
-
- Relation
- See also:
Creates a Traversable lens from an Applicative-returning function.
When executed, it 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 traverse
method of the third argument, if present.
Example
const maybeLens = RA.lensTraverse(Maybe.of);
const safeDiv = n => d => d === 0 ? Maybe.Nothing() : Maybe.Just(n / d)
R.over(maybeLens, safeDiv(10), [2, 4, 5]); // => Just([5, 2.5, 2])
R.over(maybeLens, safeDiv(10), [2, 0, 5]); // => Nothing
R.view(maybeLens, [Maybe.Just(2), Maybe.Just(3)]); // => Maybe.Just([2, 3])
R.set(maybeLens, Maybe.Just(1), [Maybe.just(2), Maybe.Just(3)]); // => Maybe.Just([1, 1])
Parameters:
Name | Type | Description |
---|---|---|
of |
function | The Applicative-returning function |
Returns:
The Traversable lens
- Type
- function
(static) liftF(fn) → {function}
- Source:
- Since:
- Signature:
-
Apply a => (a... -> a) -> (a... -> a)
- Category:
-
- Function
- See also:
"lifts" a function to be the specified arity, so that it may "map over" objects that satisfy the fantasy land Apply spec of algebraic structures.
Lifting is specific for scalaz and function Java implementations. Old version of fantasy land spec were not compatible with this approach, but as of fantasy land 1.0.0 Apply spec also adopted this approach.
This function acts as interop for ramda <= 0.23.0 and monet.js.
More info here.
Example
const { Maybe } = require('monet');
const add3 = (a, b, c) => a + b + c;
const madd3 = RA.liftF(add3);
madd3(Maybe.Some(10), Maybe.Some(15), Maybe.Some(17)); //=> Maybe.Some(42)
madd3(Maybe.Some(10), Maybe.Nothing(), Maybe.Some(17)); //=> Maybe.Nothing()
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | The function to lift into higher context |
Returns:
The lifted function
- Type
- function
(static) liftFN(arity, fn) → {function}
- Source:
- Since:
- Signature:
-
Apply a => Number -> (a... -> a) -> (a... -> a)
- Category:
-
- Function
- See also:
"lifts" a function to be the specified arity, so that it may "map over" objects that satisfy the fantasy land Apply spec of algebraic structures.
Lifting is specific for scalaz and functional java implementations. Old version of fantasy land spec were not compatible with this approach, but as of fantasy land 1.0.0 Apply spec also adopted this approach.
This function acts as interop for ramda <= 0.23.0 and monet.js.
More info here.
Example
const { Maybe } = require('monet');
const add3 = (a, b, c) => a + b + c;
const madd3 = RA.liftFN(3, add3);
madd3(Maybe.Some(10), Maybe.Some(15), Maybe.Some(17)); //=> Maybe.Some(42)
madd3(Maybe.Some(10), Maybe.Nothing(), Maybe.Some(17)); //=> Maybe.Nothing()
Parameters:
Name | Type | Description |
---|---|---|
arity |
number | The arity of the lifter function |
fn |
function | The function to lift into higher context |
Returns:
The lifted function
- Type
- function
(static) list(…items) → {Array}
- Source:
- Since:
- Signature:
-
a... -> [a...]
- Category:
-
- List
- See also:
Creates a list from arguments.
Example
RA.list('a', 'b', 'c'); //=> ['a', 'b', 'c']
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
items |
* |
<repeatable> |
The items of the feature list |
Returns:
New list created from items
- Type
- Array
(static) makeFlat(=non-null, =non-null) → (non-null) {Array}
- Source:
- Signature:
-
Bool -> List -> List
- Category:
-
- List
makeFlat
is a helper function that returns a one-level or fully recursive
function based on the flag passed in.
Parameters:
Name | Type | Description |
---|---|---|
= |
bool | should recursively flatten |
= |
Array | the nested list to be flattened |
Returns:
= the flattened list
- Type
- Array
(static) mapIndexed(fn, list) → {Array}
- Source:
- Since:
- Signature:
-
Functor f => ((a, Idx, f a) => b) => f a -> f b
-
Idx = Number
- Category:
-
- List
- See also:
R.map function that more closely resembles Array.prototype.map. It takes two new parameters to its callback function: the current index, and the entire list.
mapIndexed
implementation is simple : const mapIndexed = R.addIndex(R.map);
Example
RA.mapIndexed((val, idx, list) => idx + '-' + val, ['f', 'o', 'o', 'b', 'a', 'r']);
//=> ['0-f', '1-o', '2-o', '3-b', '4-a', '5-r']
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | The function to be called on every element of the input |
list |
Array | The list to be iterated over |
Returns:
The new list
- Type
- Array
(static) mergePath(pathnon-null, sourcenon-null, objnon-null) → (non-null) {Object}
- Source:
- Since:
- Signature:
-
[k] -> {a} -> {k: {a}} -> {k: {a}}
- Category:
-
- Object
- See also:
Create a new object with the own properties of the object under the path
merged with the own properties of the provided source
.
If a key exists in both objects, the value from the source
object will be used.
Example
RA.mergePath(
['outer', 'inner'],
{ foo: 3, bar: 4 },
{ outer: { inner: { foo: 2 } } }
); //=> { outer: { inner: { foo: 3, bar: 4 } }
Parameters:
Name | Type | Description |
---|---|---|
path |
Array | The property path of the destination object |
source |
Object | The source object |
obj |
Object | The object that has destination object under corresponding property path |
Returns:
The new version of object
- Type
- Object
(static) mergePaths(pathsnon-null, objnon-null) → (non-null) {Object}
- Source:
- Since:
- Signature:
-
[[k]] -> {k: {a}} -> {a}
- Category:
-
- Object
- See also:
Merge objects under corresponding paths.
Example
const obj = {
foo: { fooInner: { fooInner2: 1 } },
bar: { barInner: 2 }
};
{ ...obj.foo.fooInner, ...obj.bar }; //=> { fooInner2: 1, barInner: 2 }
RA.mergePaths([['foo', 'fooInner'], ['bar']], obj); //=> { fooInner2: 1, barInner: 2 }
Parameters:
Name | Type | Description |
---|---|---|
paths |
Array | The property paths to merge |
obj |
Object | The object to query |
Returns:
The object composed of merged property paths of obj
- Type
- Object
(static) mergeProp(pnon-null, sourcenon-null, objnon-null) → (non-null) {Object}
- Source:
- Since:
- Signature:
-
[k] -> {a} -> {k: {a}} -> {k: {a}}
- Category:
-
- Object
- See also:
Create a new object with the own properties of the object under the p
merged with the own properties of the provided source
.
If a key exists in both objects, the value from the source
object will be used.
Example
RA.mergeProp(
'outer',
{ foo: 3, bar: 4 },
{ outer: { foo: 2 } }
); //=> { outer: { foo: 3, bar: 4 } };
Parameters:
Name | Type | Description |
---|---|---|
p |
Array | The property of the destination object |
source |
Object | The source object |
obj |
Object | The object that has destination object under corresponding property |
Returns:
The new version of object
- Type
- Object
(static) mergeProps(psnon-null, objnon-null) → (non-null) {Object}
- Source:
- Since:
- Signature:
-
[k] -> {k: {a}} -> {a}
- Category:
-
- Object
- See also:
Functional equivalent of merging object properties with object spread operator.
Example
const obj = {
foo: { fooInner: 1 },
bar: { barInner: 2 }
};
{ ...obj.foo, ...obj.bar }; //=> { fooInner: 1, barInner: 2 }
RA.mergeProps(['foo', 'bar'], obj); //=> { fooInner: 1, barInner: 2 }
Parameters:
Name | Type | Description |
---|---|---|
ps |
Array | The property names to merge |
obj |
Object | The object to query |
Returns:
The object composed of merged properties of obj
- Type
- Object
(static) mergeRight(r, l) → {Object}
- Source:
- Since:
- Deprecated:
- since v2.12.0; available in ramda@0.26.0 as R.mergeLeft
- Signature:
-
{k: v} -> {k: v} -> {k: v}
- Aliases:
-
- mergeLeft, resetToDefault
- Category:
-
- Object
- See also:
Create a new object with the own properties of the second object merged with the own properties of the first object. If a key exists in both objects, the value from the first object will be used. * Putting it simply: it sets properties only if they don't exist.
Example
RA.mergeRight({ 'age': 40 }, { 'name': 'fred', 'age': 10 });
//=> { 'name': 'fred', 'age': 40 }
Parameters:
Name | Type | Description |
---|---|---|
r |
Object | Destination |
l |
Object | Source |
Returns:
- Type
- Object
(static) move(fromIdx, toIdx, list) → {Array}
Returns a new list with the item at the position fromIdx
moved to the position toIdx
. If the
toIdx
is out of the list
range, the item will be placed at the last position of the list
.
When negative indices are provided, the behavior of the move is unspecified.
Example
const list = ['a', 'b', 'c', 'd', 'e'];
RA.move(1, 3, list) //=> ['a', 'c', 'd', 'b', 'e']
Parameters:
Name | Type | Description |
---|---|---|
fromIdx |
number | The position of item to be moved |
toIdx |
number | The position of item after move |
list |
Array | The list containing the item to be moved |
Returns:
- Type
- Array
(static) nand(a, b) → {Boolean}
Returns false if both arguments are truthy; true otherwise.
Example
RA.nand(true, true); //=> false
RA.nand(false, true); //=> true
RA.nand(true, false); //=> true
RA.nand(false, false); //=> true
RA.nand(1.0, 1.0); //=> false
RA.nand(1.0, 0); //=> true
RA.nand(0, 1.0); //=> true
RA.nand(0, 0); //=> true
Parameters:
Name | Type | Description |
---|---|---|
a |
* | |
b |
* |
Returns:
false if both arguments are truesy
- Type
- Boolean
(static) neither(f, g) → {function}
- Source:
- Since:
- Signature:
-
(*... -> Boolean) -> (*... -> Boolean) -> (*... -> Boolean)
- Category:
-
- Logic
- See also:
A function which calls the two provided functions and returns the complement of ||
ing the
results.
It returns false if the first function is truth-y and the complement 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. In short it will return true if neither predicate
returns true.
In addition to functions, RA.neither
also accepts any fantasy-land compatible
applicative functor.
Example
const gt10 = R.gt(R.__, 10)
const even = (x) => x % 2 === 0;
const f = RA.neither(gt10, even);
f(12); //=> false
f(8); //=> false
f(11); //=> false
f(9); //=> true
Parameters:
Name | Type | Description |
---|---|---|
f |
function | A predicate |
g |
function | Another predicate |
Returns:
Returns a function that applies its arguments to f
and g
and returns the complement of ||
ing their outputs together.
- Type
- function
(static) noneP(iterable) → {Promise}
- Source:
- Since:
- Signature:
-
[Promise a] -> Promise [a]
- Category:
-
- Function
- See also:
Returns a Promise that is resolved with an array of reasons when all of the provided Promises reject, or rejected when any Promise is resolved. This pattern is like allP, but fulfillments and rejections are transposed - rejections become the fulfillment values and vice versa.
Example
RA.noneP([Promise.reject('hello'), Promise.reject('world')]); //=> Promise(['hello', 'world'])
RA.noneP([]); //=> Promise([])
RA.noneP([Promise.reject(), Promise.resolve('hello world')]); //=> Promise('hello world')
RA.noneP([Promise.reject(), 'hello world']); //=> Promise('hello world')
Parameters:
Name | Type | Description |
---|---|---|
iterable |
Iterable.<*> | An iterable object such as an Array or String |
Returns:
A Promise that is resolved with a list of rejection reasons if all Promises are rejected, or a Promise that is rejected with the fulfillment value of the first Promise that resolves.
- Type
- Promise
(static) nonePass(predicates) → {function}
- Source:
- Since:
- Signature:
-
[(*... -> Boolean)] -> (*... -> Boolean)
- Category:
-
- Logic
- See also:
Takes a list of predicates and returns a predicate that returns true for a given list of arguments if none of the provided predicates are satisfied by those arguments. It is the complement of Ramda's anyPass.
The function returned is a curried function whose arity matches that of the highest-arity predicate.
Example
const gt10 = R.gt(R.__, 10)
const even = (x) => x % 2 === 0;
const f = RA.nonePass([gt10, even]);
f(12); //=> false
f(8); //=> false
f(11); //=> false
f(9); //=> true
Parameters:
Name | Type | Description |
---|---|---|
predicates |
Array | An array of predicates to check |
Returns:
The combined predicate
- Type
- function
(static) noop() → {undefined}
A function that performs no operations.
Example
RA.noop(); //=> undefined
RA.noop(1, 2, 3); //=> undefined
Returns:
- Type
- undefined
(static) nor(a, b) → {boolean}
- Source:
- Since:
- Signature:
-
a -> b -> a ⊽ b
- Category:
-
- Logic
- See also:
Returns true if both arguments are falsy; false otherwise.
Example
RA.nor(true, true); //=> false
RA.nor(false, true); //=> false
RA.nor(true, false); //=> false
RA.nor(false, false); //=> true
RA.nor(1, 1); //=> false
RA.nor(1, 0); //=> false
RA.nor(0, 1); //=> false
RA.nor(0, 0); //=> true
Parameters:
Name | Type | Description |
---|---|---|
a |
* | |
b |
* |
Returns:
true if both arguments are falsy
- Type
- boolean
(static) notAllPass(predicates) → {function}
- Source:
- Since:
- Signature:
-
[(*... -> Boolean)] -> (*... -> Boolean)
- Category:
-
- Logic
- See also:
Takes a list of predicates and returns a predicate that returns true for a given list of arguments if one or more of the provided predicates is not satisfied by those arguments. It is the complement of Ramda's allPass.
The function returned is a curried function whose arity matches that of the highest-arity predicate.
Example
const gt10 = R.gt(R.__, 10)
const even = (x) => x % 2 === 0;
const f = RA.notAllPass([gt10, even]);
f(12); //=> false
f(8); //=> true
f(11); //=> true
f(9); //=> true
Parameters:
Name | Type | Description |
---|---|---|
predicates |
Array | An array of predicates to check |
Returns:
The combined predicate
- Type
- function
(static) notAllUnique(list) → {boolean}
- Source:
- Since:
- Signature:
-
[a] -> Boolean
- Category:
-
- List
- See also:
Returns true if at least one item of the list is repeated. R.equals
is used to determine equality.
Example
RA.notAllUnique([ 1, 1, 2, 3 ]); //=> true
RA.notAllUnique([ 1, 2, 3, 4 ]); //=> false
RA.notAllUnique([]); //=> false
Parameters:
Name | Type | Description |
---|---|---|
list |
Array | The list of values |
Returns:
- Type
- boolean
(static) notBoth(f, g) → {function}
- Source:
- Since:
- Signature:
-
(*... -> Boolean) -> (*... -> Boolean) -> (*... -> Boolean)
- Category:
-
- Logic
- See also:
A function which calls the two provided functions and returns the complement of &&
ing the
results.
It returns true if the first function is false-y and the complement 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. In short it will return true unless both predicates
return true.
In addition to functions, RA.notBoth
also accepts any fantasy-land compatible
applicative functor.
Example
const gt10 = R.gt(R.__, 10)
const even = (x) => x % 2 === 0;
const f = RA.notBoth(gt10, even);
f(12); //=> false
f(8); //=> true
f(11); //=> true
f(9); //=> true
Parameters:
Name | Type | Description |
---|---|---|
f |
function | A predicate |
g |
function | Another predicate |
Returns:
Returns a function that applies its arguments to f
and g
and returns the complement of &&
ing their outputs together.
- Type
- function
(static) notEqual(a, b) → {Boolean}
- Source:
- Since:
- Signature:
-
a -> b -> Boolean
- Category:
-
- Relation
- See also:
Returns true
if its arguments are not equivalent, false
otherwise. Handles
cyclical data structures.
Dispatches symmetrically to the equals
methods of both arguments, if
present.
Example
RA.notEqual(1, 1); //=> false
RA.notEqual(1, '1'); //=> true
RA.notEqual([1, 2, 3], [1, 2, 3]); //=> false
const a = {}; a.v = a;
const b = {}; b.v = b;
RA.notEqual(a, b); //=> false
Parameters:
Name | Type | Description |
---|---|---|
a |
* | |
b |
* |
Returns:
- Type
- Boolean
(static) omitBy(prednon-null, objnon-null) → (non-null) {Object}
- Source:
- Since:
- Signature:
-
((v, k) -> Boolean) -> {k: v} -> {k: v}
- Category:
-
- Object
Returns a partial copy of an object containing only the keys that don't satisfy the supplied predicate.
Example
const isLowerCase = (val, key) => key.toLowerCase() === key;
RA.omitBy(isLowerCase, {a: 1, b: 2, A: 3, B: 4}); //=> {A: 3, B: 4}
Parameters:
Name | Type | Description |
---|---|---|
pred |
function | A predicate to determine whether or not a key should be included on the output object |
obj |
Object | The object to copy from |
Returns:
A new object only with properties that don't satisfy pred
- Type
- Object
(static) omitIndexes(indexesnon-null, listnon-null) → (non-null) {Array}
- Source:
- Since:
- Signature:
-
[Int] -> [a] -> [a]
- Category:
-
- List
- See also:
Returns a partial copy of an array omitting the indexes specified.
Example
RA.omitIndexes([-1, 1, 3], ['a', 'b', 'c', 'd']); //=> ['a', 'c']
Parameters:
Name | Type | Description |
---|---|---|
indexes |
Array | The array of indexes to omit from the new array |
list |
Array | The array to copy from |
Returns:
The new array with omitted indexes
- Type
- Array
(static) overlaps(list1, list2) → {boolean}
- Source:
- Since:
- Signature:
-
[a] -> [a] -> Boolean
- Category:
-
- Relation
Returns true if two lists have at least one element common to both lists.
Example
RA.overlaps(['-v', '--verbose'], ['node', 'script.js', '-v']); //=> true
RA.overlaps(['-v', '--verbose'], []); //=> false
RA.overlaps([1, 2, 3], [3, 4, 5]); //=> true
RA.overlaps([1, 2, 3], [4, 5]); //=> false
Parameters:
Name | Type | Description |
---|---|---|
list1 |
Array | The first list |
list2 |
Array | The second list |
Returns:
True if two lists have at least one element common to both lists
- Type
- boolean
(static) padCharsEnd(padString, targetLength, value) → {string}
- Source:
- Since:
- Signature:
-
String -> Number -> String -> String
- Category:
-
- String
- See also:
The function pads the current string with a given string (repeated, if needed) so that the resulting string reaches a given length. The padding is applied from the end of the current string.
Example
RA.padCharsEnd('-', 3, 'a'); // => 'a--'
RA.padCharsEnd('foo', 10, 'abc'); // => 'abcfoofoof'
RA.padCharsEnd('123456', 6, 'abc'); // => 'abc123'
Parameters:
Name | Type | Description |
---|---|---|
padString |
string | The string to pad the current string with |
targetLength |
number | The length of the resulting string once the current string has been padded |
value |
string | String value to be padded |
Returns:
A new string of the specified length with the pad string applied at the end of the current string
- Type
- string
(static) padCharsStart(padString, targetLength, value) → {string}
- Source:
- Since:
- Signature:
-
String -> Number -> String -> String
- Category:
-
- String
- See also:
The function pads the current string with a given string (repeated, if needed) so that the resulting string reaches a given length. The padding is applied from the start of the current string.
Example
RA.padCharsStart('-', 3, 'a'); // => '--a'
RA.padCharsStart('foo', 10, 'abc'); // => 'foofoofabc'
RA.padCharsStart('123456', 6, 'abc'); // => '123abc'
Parameters:
Name | Type | Description |
---|---|---|
padString |
string | The string to pad the current string with |
targetLength |
number | The length of the resulting string once the current string has been padded |
value |
string | String value to be padded |
Returns:
A new string of the specified length with the pad string on the start of current string
- Type
- string
(static) padEnd(targetLength, value) → {string}
- Source:
- Since:
- Signature:
-
Number -> String -> String
- Category:
-
- String
- See also:
The function pads the current string with an empty string so that the resulting string reaches a given length. The padding is applied from the end of the current string.
Example
RA.padEnd(3, 'a'); // => 'a '
Parameters:
Name | Type | Description |
---|---|---|
targetLength |
number | The length of the resulting string once the current string has been padded |
value |
string | String value to be padded |
Returns:
A new string of the specified length with the pad string applied at the end of the current string
- Type
- string
(static) padStart(targetLength, value) → {string}
- Source:
- Since:
- Signature:
-
Number -> String -> String
- Category:
-
- String
- See also:
Pads string on the left side if it's shorter than length.
Example
RA.padStart(3, 'a'); // => ' a'
Parameters:
Name | Type | Description |
---|---|---|
targetLength |
number | The length of the resulting string once the current string has been padded |
value |
string | String value to be padded |
Returns:
A new string of the specified length with the empty string applied to the beginning of the current string
- Type
- string
(static) pathNotEq(path, val, object) → {boolean}
- Source:
- Since:
- Signature:
-
[Idx] => a => {a} => Boolean
Idx = String | Int
- Category:
-
- Relation
- See also:
Determines whether a nested path on an object doesn't have a specific value, in R.equals terms. Most likely used to filter a list.
Example
const user1 = { address: { zipCode: 90210 } };
const user2 = { address: { zipCode: 55555 } };
const user3 = { name: 'Bob' };
const users = [ user1, user2, user3 ];
const isFamous = R.pathNotEq(['address', 'zipCode'], 90210);
R.filter(isFamous, users); //=> [ user2, user3 ]
Parameters:
Name | Type | Description |
---|---|---|
path |
Array | The path of the nested property to use |
val |
a | The value to compare the nested property with |
object |
Object | The object to check the nested property in |
Returns:
Returns Boolean false
if the value equals the nested object property, true
otherwise
- Type
- boolean
(static) pathOrLazy(defaultFn, path, obj) → {*}
- Source:
- Since:
- Signature:
-
({a} -> a) -> [Idx] -> {a} -> a
-
Idx = String | Int
- Category:
-
- Object
If the given, non-null object has a value at the given path, returns the value at that path. Otherwise returns the result of invoking the provided function with the object.
Example
RA.pathOrLazy(() => 'N/A', ['a', 'b'], {a: {b: 2}}); //=> 2
RA.pathOrLazy(() => 'N/A', ['a', 'b'], {c: {b: 2}}); //=> "N/A"
Parameters:
Name | Type | Description |
---|---|---|
defaultFn |
function | The function that will return the default value. |
path |
Array | The path to use. |
obj |
Object | The object to retrieve the nested property from. |
Returns:
The data at path
of the supplied object or the default value.
- Type
- *
(static) paths(ps, obj) → {Array}
- Source:
- Since:
- Signature:
-
[[k]] -> {k: v} - [v]
- Category:
-
- List
- See also:
Acts as multiple path: arrays of paths in, array of values out. Preserves order.
Example
const obj = {
a: { b: { c: 1 } },
x: 2,
};
RA.paths([['a', 'b', 'c'], ['x']], obj); //=> [1, 2]
Parameters:
Name | Type | Description |
---|---|---|
ps |
Array | The property paths to fetch |
obj |
Object | The object to query |
Returns:
The corresponding values or partially applied function
- Type
- Array
(static) pickIndexes(indexes, list) → {Array}
- Source:
- Since:
- Signature:
-
[Number] -> [a] -> [a]
- Category:
-
- List
- See also:
Picks values from list by indexes.
Note: pickIndexes will skip non existing indexes. If you want to include them
use ramda's props
function.
Example
RA.pickIndexes([0, 2], ['a', 'b', 'c']); //=> ['a', 'c']
Parameters:
Name | Type | Description |
---|---|---|
indexes |
Array | The indexes to pick |
list |
Array | The list to pick values from |
Returns:
New array containing only values at indexes
- Type
- Array
(static) propNotEq(name, val, object) → {boolean}
- Source:
- Since:
- Signature:
-
String -> a -> Object -> Boolean
- Category:
-
- Relation
- See also:
Returns true if the specified object property is not equal, in R.equals terms, to the given value; false otherwise.
Example
const abby = { name: 'Abby', age: 7, hair: 'blond' };
const fred = { name: 'Fred', age: 12, hair: 'brown' };
const rusty = { name: 'Rusty', age: 10, hair: 'brown' };
const alois = { name: 'Alois', age: 15, disposition: 'surly' };
const kids = [abby, fred, rusty, alois];
const hasNotBrownHair = RA.propNotEq('hair', 'brown');
R.filter(hasNotBrownHair, kids); //=> [abby, alois]
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The property to pick |
val |
a | The value to compare to |
object |
Object | The object, that presumably contains value under the property |
Returns:
Comparison result
- Type
- boolean
(static) rangeStep(step, from, to) → {Array.<number>}
- Source:
- Since:
- Signature:
-
Number -> Number -> Number -> [Number]
- Category:
-
- List
- See also:
Creates an array of numbers (positive and/or negative) progressing from start up to, but not including, end.
Note
: JavaScript follows the IEEE-754 standard for resolving floating-point values which can produce unexpected results.
Example
RA.rangeStep(1, 0, 4); // => [0, 1 ,2, 3]
RA.rangeStep(-1, 0, -4); // => [0, -1, -2, -3]
RA.rangeStep(1, 1, 5); // => [1, 2, 3, 4]
RA.rangeStep(5, 0, 20); // => [0, 5, 10, 15]
RA.rangeStep(-1, 0, -4); // => [0, -1, -2, -3]
RA.rangeStep(0, 1, 4); // => [1, 1, 1]
RA.rangeStep(1, 0, 0); // => []
Parameters:
Name | Type | Description |
---|---|---|
step |
number | The value to increment or decrement by |
from |
number | The start of the range |
to |
number | The end of the range |
Returns:
Returns the range of numbers
- Type
- Array.<number>
(static) reduceIndexed(fn, acc, list) → {*}
- Source:
- Since:
- Signature:
-
((a, b, Idx, [b]) => a) -> a -> [b] -> a
-
Idx = Number
- Category:
-
- List
- See also:
R.reduce function that more closely resembles Array.prototype.reduce. It takes two new parameters to its callback function: the current index, and the entire list.
reduceIndexed
implementation is simple : const reduceIndexed = R.addIndex(R.reduce);
Example
const initialList = ['f', 'o', 'o', 'b', 'a', 'r'];
reduceIndexed((acc, val, idx, list) => acc + '-' + val + idx, '', initialList);
//=> "-f0-o1-o2-b3-a4-r5"
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | The iterator function. Receives four values, the accumulator, the current element from the array, index and the entire list |
acc |
* | The accumulator value |
list |
Array | The list to iterate over |
Returns:
The final, accumulated value
- Type
- *
(static) reduceP(fn, acc, list) → {Promise}
- Source:
- Since:
- Signature:
-
((Promise a, MaybePromise b) -> Promise a) -> MaybePromise a -> MaybePromise [MaybePromise b] -> Promise a
-
MaybePromise = Promise.<*> | *
- Category:
-
- List
- See also:
Given an Iterable
(arrays are Iterable
), or a promise of an Iterable
,
which produces promises (or a mix of promises and values),
iterate over all the values in the Iterable
into an array and
reduce the array to a value using the given iterator function.
If the iterator function returns a promise, then the result of the promise is awaited, before continuing with next iteration. If any promise in the array is rejected or a promise returned by the iterator function is rejected, the result is rejected as well.
If initialValue
is undefined
(or a promise that resolves to undefined
) and
the Iterable
contains only 1 item, the callback will not be called and
the Iterable's
single item is returned. If the Iterable
is empty, the callback
will not be called and initialValue
is returned (which may be undefined).
This function is basically equivalent to bluebird.reduce.
Example
RA.reduceP(
(total, fileName) => fs
.readFileAsync(fileName, 'utf8')
.then(contents => total + parseInt(contents, 10)),
0,
['file1.txt', 'file2.txt', 'file3.txt']
); // => Promise(10)
RA.reduceP(
(total, fileName) => fs
.readFileAsync(fileName, 'utf8')
.then(contents => total + parseInt(contents, 10)),
Promise.resolve(0),
['file1.txt', 'file2.txt', 'file3.txt']
); // => Promise(10)
RA.reduceP(
(total, fileName) => fs
.readFileAsync(fileName, 'utf8')
.then(contents => total + parseInt(contents, 10)),
0,
[Promise.resolve('file1.txt'), 'file2.txt', 'file3.txt']
); // => Promise(10)
RA.reduceP(
(total, fileName) => fs
.readFileAsync(fileName, 'utf8')
.then(contents => total + parseInt(contents, 10)),
0,
Promise.resolve([Promise.resolve('file1.txt'), 'file2.txt', 'file3.txt'])
); // => Promise(10)
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | The iterator function. Receives two values, the accumulator and the current element from the list |
acc |
* | Promise.<*> | The accumulator value |
list |
Array.<*> | Promise.<Array.<(*|Promise.<*>)>> | The list to iterate over |
Returns:
The final, accumulated value
- Type
- Promise
(static) reduceRightP(fn, acc, list) → {Promise}
- Source:
- Since:
- Signature:
-
((MaybePromise b, Promise a) -> Promise a) -> MaybePromise a -> MaybePromise [MaybePromise b] -> Promise a
-
MaybePromise = Promise.<*> | *
- Category:
-
- List
- See also:
Given an Iterable
(arrays are Iterable
), or a promise of an Iterable
,
which produces promises (or a mix of promises and values),
iterate over all the values in the Iterable
into an array and
reduce the array to a value using the given iterator function.
Similar to reduceP
except moves through the input list from the right to the left.
The iterator function receives two values: (value, acc),
while the arguments' order of reduceP's iterator function is (acc, value).
Example
RA.reduceRightP(
(fileName, total) => fs
.readFileAsync(fileName, 'utf8')
.then(contents => total + parseInt(contents, 10)),
0,
['file1.txt', 'file2.txt', 'file3.txt']
); // => Promise(10)
RA.reduceRightP(
(fileName, total) => fs
.readFileAsync(fileName, 'utf8')
.then(contents => total + parseInt(contents, 10)),
Promise.resolve(0),
['file1.txt', 'file2.txt', 'file3.txt']
); // => Promise(10)
RA.reduceRightP(
(fileName, total) => fs
.readFileAsync(fileName, 'utf8')
.then(contents => total + parseInt(contents, 10)),
0,
[Promise.resolve('file1.txt'), 'file2.txt', 'file3.txt']
); // => Promise(10)
RA.reduceRightP(
(fileName, total) => fs
.readFileAsync(fileName, 'utf8')
.then(contents => total + parseInt(contents, 10)),
0,
Promise.resolve([Promise.resolve('file1.txt'), 'file2.txt', 'file3.txt'])
); // => Promise(10)
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | The iterator function. Receives two values, the current element from the list and the accumulator |
acc |
* | Promise.<*> | The accumulator value |
list |
Array.<*> | Promise.<Array.<(*|Promise.<*>)>> | The list to iterate over |
Returns:
The final, accumulated value
- Type
- Promise
(static) rejectP(reasonopt) → {Promise}
- Source:
- Since:
- Signature:
-
a -> Promise a
- Category:
-
- Function
- See also:
Composable shortcut for Promise.reject
.
Returns a Promise object that is rejected with the given reason.
Example
RA.rejectP(); //=> Promise(undefined)
RA.rejectP('a'); //=> Promise('a')
RA.rejectP([1, 2, 3]); //=> Promise([1, 2, 3])
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
reason |
* |
<optional> |
Reason why this Promise rejected |
Returns:
A Promise that is rejected with the given reason
- Type
- Promise
(static) renameKeys(keysMapnon-null, objnon-null) → (non-null) {Object}
- Source:
- Since:
- Signature:
-
{a: b} -> {a: *} -> {b: *}
- Category:
-
- Object
- See also:
Creates a new object with the own properties of the provided object, but the
keys renamed according to the keysMap object as {oldKey: newKey}
.
When some key is not found in the keysMap, then it's passed as-is.
Keep in mind that in the case of keys conflict is behaviour undefined and the result may vary between various JS engines!
Example
const input = { firstName: 'Elisia', age: 22, type: 'human' };
RA.renameKeys({ firstName: 'name', type: 'kind', foo: 'bar' })(input);
//=> { name: 'Elisia', age: 22, kind: 'human' }
Parameters:
Name | Type | Description |
---|---|---|
keysMap |
Object | |
obj |
Object |
Returns:
New object with renamed keys
- Type
- Object
(static) renameKeysWith(fn, objnon-null) → (non-null) {Object}
- Source:
- Since:
- Signature:
-
(a -> b) -> {a: *} -> {b: *}
- Category:
-
- Object
- See also:
Creates a new object with the own properties of the provided object, but the keys renamed according to logic of renaming function.
Keep in mind that in the case of keys conflict is behaviour undefined and the result may vary between various JS engines!
Example
RA.renameKeysWith(R.concat('a'), { A: 1, B: 2, C: 3 }) //=> { aA: 1, aB: 2, aC: 3 }
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | Function that renames the keys |
obj |
Object | Provided object |
Returns:
New object with renamed keys
- Type
- Object
(static) renameKeyWith(fn, keynon-null, objnon-null) → (non-null) {Object}
- Source:
- Since:
- Signature:
-
(k -> k) -> k -> {k: v} -> {k: v}
- Category:
-
- Object
- See also:
Creates a new object with the own properties of the provided object, but the
key key
renamed according to logic of renaming function.
Keep in mind that in case the new key name already existed on the object, the behaviour is undefined and the result may vary between various JS engines!
Example
RA.renameKeyWith(R.concat('a'), 'A', { A: 1 }) //=> { aA: 1 }
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | Function that renames the keys |
key |
string | Key to rename |
obj |
Object | Provided object |
Returns:
New object with renamed key
- Type
- Object
(static) repeatStr(value, count) → {string}
- Source:
- Since:
- Signature:
-
String -> Number -> String
- Category:
-
- List
Constructs and returns a new string which contains the specified number of copies of the string on which it was called, concatenated together.
Example
RA.repeatStr('a', 3); //=> 'aaa'
Parameters:
Name | Type | Description |
---|---|---|
value |
string | String value to be repeated |
count |
number | An integer between 0 and +∞: [0, +∞), indicating the number of times to repeat the string in the newly-created string that is to be returned |
Returns:
A new string containing the specified number of copies of the given string
- Type
- string
(static) replaceAll(searchValue, replaceValue, str) → {string}
- Source:
- Since:
- Signature:
-
String -> String -> String -> String
- Category:
-
- String
- See also:
Replaces all substring matches in a string with a replacement.
Example
RA.replaceAll('ac', 'ef', 'ac ab ac ab'); //=> 'ef ab ef ab'
RA.replaceAll('', '_', 'xxx'); //=> '_x_x_x_'
RA.replaceAll(/x/g, 'v', 'xxx'); //=> 'vvv'
RA.replaceAll(/x/, 'v', 'xxx'); //=> TypeError
Parameters:
Name | Type | Description |
---|---|---|
searchValue |
string | The substring or a global RegExp to match |
replaceValue |
string | The string to replace the matches with |
str |
string | The String to do the search and replacement in |
Throws:
-
When invalid arguments provided
- Type
- TypeError
Returns:
A new string containing all the searchValue
replaced with the replaceValue
- Type
- string
(static) resolveP(valueopt) → {Promise}
- Source:
- Since:
- Signature:
-
a -> Promise a
- Category:
-
- Function
- See also:
Composable shortcut for Promise.resolve
.
Returns a Promise object that is resolved with the given value. If the value is a thenable (i.e. has a "then" method), the returned promise will "follow" that thenable, adopting its eventual state.
Example
RA.resolveP(); //=> Promise(undefined)
RA.resolveP('a'); //=> Promise('a')
RA.resolveP([1, 2, 3]); //=> Promise([1, 2, 3])
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
value |
* |
<optional> |
Argument to be resolved by this Promise. Can also be a Promise or a thenable to resolve |
Returns:
A Promise that is resolved with the given value, or the promise passed as value, if the value was a promise object
- Type
- Promise
(static) round(number) → {number}
Returns the value of a number rounded to the nearest integer.
Example
RA.round(0.9); //=> 1
RA.round(5.95); //=> 6
RA.round(5.5); //=> 6
RA.round(5.05); //=> 5
RA.round(-5.05); //=> -5
RA.round(-5.5); //=> -5
RA.round(-5.95); //=> -6
Parameters:
Name | Type | Description |
---|---|---|
number |
number | The number to round |
Returns:
The value of the given number rounded to the nearest integer
- Type
- number
(static) seq(fns, x) → {*}
- Source:
- Since:
- Signature:
-
[(a -> *), (a -> *), ...] -> a -> a
- Aliases:
-
- sequencing
- Category:
-
- Function
- See also:
Runs the given list of functions in order with the supplied object, then returns the object. Also known as the normal order sequencing combinator.
Acts as a transducer if a transformer is given as second parameter.
Example
RA.seq([console.info, console.log])('foo'); //=> prints 'foo' via info then log
// usage in composition
R.pipe(
R.concat('prefix '),
RA.seq([
console.info, //=> prints 'prefix test'
console.log //=> prints 'prefix test'
]),
R.toUpper
)('test'); //=> 'PREFIX TEST'
Parameters:
Name | Type | Description |
---|---|---|
fns |
Array | The list of functions to call in order with |
x |
* |
Returns:
x
- Type
- *
(static) sign(number) → {number}
Returns the sign of a number, indicating whether the number is positive, negative or zero.
Example
RA.sign(3); // 1
RA.sign(-3); // -1
RA.sign('-3'); // -1
RA.sign(0); // 0
RA.sign(-0); // -0
RA.sign(NaN); // NaN
RA.sign('foo'); // NaN
Parameters:
Name | Type | Description |
---|---|---|
number |
number | A number |
Returns:
A number representing the sign of the given argument. If the argument is a positive number, negative number, positive zero or negative zero, the function will return 1, -1, 0 or -0 respectively. Otherwise, NaN is returned
- Type
- number
(static) skipTake(the, value) → {Array}
- Source:
- Since:
- Signature:
-
Number -> [a] -> [a]
- Category:
-
- List
When given a number n and an array, returns an array containing every nth element.
Example
RA.skipTake(2, [1,2,3,4]) //=> [1, 3]
RA.skipTake(3, R.range(0, 20)); //=> [0, 3, 6, 9, 12, 15, 18]
Parameters:
Name | Type | Description |
---|---|---|
the |
number | nth element to extract |
value |
Array | the input array |
Returns:
An array containing every nth element
- Type
- Array
(static) sliceFrom(fromIndex, list) → {Array|string}
- Source:
- Since:
- Signature:
-
Number -> [a] -> [a]
- Category:
-
- List
- See also:
Returns the elements of the given list or string (or object with a slice method) from fromIndex (inclusive). Dispatches to the slice method of the second argument, if present.
Example
RA.sliceFrom(1, [1, 2, 3]); //=> [2, 3]
Parameters:
Name | Type | Description |
---|---|---|
fromIndex |
number | The start index (inclusive) |
list |
Array | string | The list or string to slice |
Returns:
The sliced list or string
- Type
- Array | string
(static) sliceTo(toIndex, list) → {Array|string}
- Source:
- Since:
- Signature:
-
Number -> [a] -> [a]
- Category:
-
- List
- See also:
Returns the elements of the given list or string (or object with a slice method) to toIndex (exclusive). Dispatches to the slice method of the second argument, if present.
Example
RA.sliceTo(2, [1, 2, 3]); //=> [1, 2]
Parameters:
Name | Type | Description |
---|---|---|
toIndex |
number | The end index (exclusive) |
list |
Array | string | The list or string to slice |
Returns:
The sliced list or string
- Type
- Array | string
(static) sortByProps(props, list) → {Array.<object>}
- Source:
- Since:
- Signature:
-
[k] -> [{k: v}] -> [{k: v}]
- Category:
-
- List
Sort a list of objects by a list of props (if first prop value is equivalent, sort by second, etc).
Example
sortByProps(['num'], [{num: 3}, {num: 2}, {num: 1}])
//=> [{num: 1}, {num: 2} {num: 3}]
sortByProps(['letter', 'num'], [{num: 3, letter: 'a'}, {num: 2, letter: 'a'} {num: 1, letter: 'z'}])
//=> [ {num: 2, letter: 'a'}, {num: 3, letter: 'a'}, {num: 1, letter: 'z'}]
sortByProps(['name', 'num'], [{num: 3}, {num: 2}, {num: 1}])
//=> [{num: 1}, {num: 2}, {num: 3}]
Parameters:
Name | Type | Description |
---|---|---|
props |
Array.<string> | A list of properties in the list param to sort by |
list |
Array.<object> | A list of objects to be sorted |
Returns:
A new list sorted by the properties in the props param
- Type
- Array.<object>
(static) spreadPath(pathnon-null, objnon-null) → (non-null) {Object}
- Source:
- Since:
- Signature:
-
[Idx] -> {k: v} -> {k: v}
-
Idx = String | Int
- Category:
-
- Object
- See also:
Spreads object under property path onto provided object.
It's like flattenPath
, but removes object under the property path.
Example
RA.spreadPath(
['b1', 'b2'],
{ a: 1, b1: { b2: { c: 3, d: 4 } } }
); // => { a: 1, c: 3, d: 4, b1: {} };
Parameters:
Name | Type | Description |
---|---|---|
path |
Array.<(string|number)> | The property path to spread |
obj |
Object | The provided object |
Returns:
The result of the spread
- Type
- Object
(static) spreadProp(prop, objnon-null) → (non-null) {Object}
- Source:
- Since:
- Signature:
-
Idx -> {k: v} -> {k: v}
-
Idx = String | Int
- Category:
-
- Object
- See also:
Spreads object under property onto provided object.
It's like flattenProp
, but removes object under the property.
Example
RA.spreadProp('b', { a: 1, b: { c: 3, d: 4 } }); // => { a: 1, c: 3, d: 4 };
Parameters:
Name | Type | Description |
---|---|---|
prop |
string | number | The property to spread |
obj |
Object | The provided object |
Returns:
The result of the spread
- Type
- Object
(static) stubArray() → {Array}
- Source:
- Since:
- Signature:
-
... -> Array
- Category:
-
- Function
A function that returns new empty array on every call.
Example
RA.stubArray(); //=> []
RA.stubArray(1, 2, 3); //=> []
Returns:
New empty array
- Type
- Array
(static) stubNull() → {null}
- Source:
- Since:
- Signature:
-
... -> null
- Category:
-
- Function
A function that returns null
.
Example
RA.stubNull(); //=> null
RA.stubNull(1, 2, 3); //=> null
Returns:
- Type
- null
(static) stubObj() → {Object}
- Source:
- Since:
- Signature:
-
... -> Object
- Aliases:
-
- stubObject
- Category:
-
- Function
This function returns a new empty object.
Example
RA.stubObj(); //=> {}
RA.stubObj(1, 2, 3); //=> {}
Returns:
Returns the new empty object.
- Type
- Object
(static) stubString() → {string}
- Source:
- Since:
- Signature:
-
... -> String
- Category:
-
- Function
A function that returns empty string.
Example
RA.stubString(); //=> ''
RA.stubString(1, 2, 3); //=> ''
Returns:
The empty string
- Type
- string
(static) stubUndefined() → {undefined}
- Source:
- Since:
- Signature:
-
... -> undefined
- Category:
-
- Function
A function that returns undefined
.
Example
RA.stubUndefined(); //=> undefined
RA.stubUndefined(1, 2, 3); //=> undefined
Returns:
- Type
- undefined
(static) subtractNum(subtrahend, minuend) → {number}
- Source:
- Since:
- Signature:
-
Number -> Number -> Number
- Category:
-
- Math
Subtracts its first argument from its second argument.
Example
RA.subtractNum(3, 5); //=> 2
Parameters:
Name | Type | Description |
---|---|---|
subtrahend |
number | the number to subtract |
minuend |
number | the number to subtract from |
Returns:
A number representing the difference of subtracting the subtrahend from the minuend
- Type
- number
(static) thenCatchP(onFulfilled, onRejected, promise) → {Promise}
- Source:
- Since:
- Signature:
-
(a -> b) -> (c -> d) -> Promise a -> Promise b | d
- Category:
-
- Function
- See also:
Composable shortcut for Promise.then
that allows for success and failure callbacks.
The thenCatchP function returns a Promise. It takes three arguments: a callback function for the success of the Promise,
a callback function for the failure of the Promise, and the promise instance itself.
Example
const promise = Promise.resolve(1);
const add1 = x => x + 1;
RA.thenCatchP(add1, console.error, promise); // => Promise(2)
Parameters:
Name | Type | Description |
---|---|---|
onFulfilled |
function | A Function called if the Promise is fulfilled. This function has one argument, the fulfillment value |
onRejected |
function | A Function called if the Promise is rejected. This function has one argument, the error |
promise |
Promise | Any Promise or Thenable object |
Returns:
- Type
- Promise
(static) thenP(onFulfilled, promise) → {Promise}
- Source:
- Since:
- Deprecated:
- since v2.12.0; available in ramda@0.26.0 as R.then
- Signature:
-
(a -> Promise b | b) -> Promise b
- Aliases:
-
- then
- Category:
-
- Function
- See also:
Composable shortcut for Promise.then
.
The thenP function returns a Promise. It takes two arguments: a callback function for the success of the Promise
and the promise instance itself.
Example
const promise = Promise.resolve(1);
const add1 = v => v + 1;
RA.thenP(add1, promise); // => Promise(2)
Parameters:
Name | Type | Description |
---|---|---|
onFulfilled |
function | A Function called if the Promise is fulfilled. This function has one argument, the fulfillment value |
promise |
Promise | Any Promise or Thenable object |
Returns:
A Promise in the pending status
- Type
- Promise
(static) toArray(val) → {Array}
- Source:
- Since:
- Signature:
-
* -> [a]
- Category:
-
- List
Converts value to an array.
Example
RA.toArray([1, 2]); //=> [1, 2]
RA.toArray({'foo': 1, 'bar': 2}); //=> [1, 2]
RA.toArray('abc'); //=> ['a', 'b', 'c']
RA.toArray(1); //=> []
RA.toArray(null); //=> []
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to convert |
Returns:
- Type
- Array
(static) toInteger32(number) → {number}
- Source:
- Since:
- Signature:
-
Number -> Number
- Aliases:
-
- toInt32
- Category:
-
- Math
- See also:
Converts double-precision 64-bit binary format IEEE 754 to signed 32 bit integer number.
Example
RA.toInteger32(2 ** 35); // => 0
RA.toInteger32(2 ** 30); // => 1073741824
Parameters:
Name | Type | Description |
---|---|---|
number |
number | A number |
Returns:
A signed 32-bit integer number
- Type
- number
(static) toNumber(val) → {Number}
- Source:
- Since:
- Category:
-
- Type
Converts value to a number.
Example
RA.toNumber(3.2); //=> 3.2
RA.toNumber(Number.MIN_VALUE); //=> 5e-324
RA.toNumber(Infinity); //=> Infinity
RA.toNumber('3.2'); //=> 3.2
RA.toNumber(Symbol('3.2')); //=> NaN
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to convert |
Returns:
- Type
- Number
(static) toUinteger32(val) → {number}
- Source:
- Since:
- Signature:
-
Number -> Number
- Aliases:
-
- toUint32
- Category:
-
- Math
- See also:
Converts double-precision 64-bit binary format IEEE 754 to unsigned 32 bit integer number.
Example
RA.toUinteger32(1.5); //=> 1
RA.toInteger32(2 ** 35); // => 0
RA.toInteger32(2 ** 31); // => 2147483648
RA.toInteger32(2 ** 30); // => 1073741824
Parameters:
Name | Type | Description |
---|---|---|
val |
number | Value to be converted. |
Returns:
- Type
- number
(static) trimCharsEnd(chars, value) → {string}
- Source:
- Since:
- Signature:
-
String -> String
- Category:
-
- String
Removes specified characters from the end of a string.
Example
RA.trimCharsEnd('_-', '-_-abc-_-'); //=> '-_-abc'
Parameters:
Name | Type | Description |
---|---|---|
chars |
string | The characters to trim |
value |
string | The string to trim |
Returns:
Returns the trimmed string.
- Type
- string
(static) trimCharsStart(chars, value) → {string}
- Source:
- Since:
- Signature:
-
String -> String
- Category:
-
- String
Removes specified characters from the beginning of a string.
Example
RA.trimCharsStart('_-', '-_-abc-_-'); //=> 'abc-_-'
Parameters:
Name | Type | Description |
---|---|---|
chars |
string | The characters to trim |
value |
string | The string to trim |
Returns:
Returns the trimmed string.
- Type
- string
(static) trimEnd(value) → {string}
- Source:
- Since:
- Signature:
-
String -> String
- Category:
-
- String
- See also:
Removes whitespace from the end of a string.
Example
RA.trimEnd('abc '); //=> 'abc'
Parameters:
Name | Type | Description |
---|---|---|
value |
string | String value to have the whitespace removed from the end |
Returns:
A new string representing the calling string stripped of whitespace from its end (right end).
- Type
- string
(static) trimStart(value) → {string}
- Source:
- Since:
- Signature:
-
String -> String
- Category:
-
- String
Removes whitespace from the beginning of a string.
Example
RA.trimStart(' abc'); //=> 'abc'
Parameters:
Name | Type | Description |
---|---|---|
value |
string | String value to have the whitespace removed from the beginning |
Returns:
A new string representing the calling string stripped of whitespace from its beginning (left end).
- Type
- string
(static) trunc(number) → {number}
Returns the integer part of a number by removing any fractional digits.
Example
RA.trunc(13.37); //=> 13
RA.trunc(42.84); //=> 42
RA.trunc(0.123); //=> 0
RA.trunc(-0.123); //=> -0
RA.trunc('-1.123'); //=> -1
RA.trunc(NaN); //=> NaN
RA.trunc('foo'); //=> NaN
Parameters:
Name | Type | Description |
---|---|---|
number |
number | string | The number to trunc |
Returns:
The integer part of the given number
- Type
- number
(static) unzipObjWith(fn, obj) → {Array}
- Source:
- Since:
- Signature:
-
(v, k) => [k, v] -> { k: v } -> [[k], [v]]
- Category:
-
- Object
- See also:
Creates a new list out of the supplied object by applying the function to each key/value pairing.
Example
RA.unzipObjWith((v, k) => [`new${k.toUpperCase()}`, 2 * v], { a: 1, b: 2, c: 3 });
//=> [['newA', 'newB', 'newC'], [2, 4, 6]]
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | The function to transform each value-key pair |
obj |
Object | Object to unzip |
Returns:
A pair of tw lists: a list of keys and a list of values
- Type
- Array
(static) viewOr(defaultValue, lens, data) → {*}
- Source:
- Since:
- Signature:
-
a -> Lens s b -> s -> b | a
-
Lens s b = Functor f => (b -> f b) -> s -> f s
- Category:
-
- Object
- See also:
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. Returns the defaultValue if "view" is null, undefined or NaN; otherwise the "view" is returned.
Example
RA.viewOr('N/A', R.lensProp('x'), {}); // => 'N/A'
RA.viewOr('N/A', R.lensProp('x'), { x: 1 }); // => 1
RA.viewOr('some', R.lensProp('y'), { y: null }); // => 'some'
RA.viewOr('some', R.lensProp('y'), { y: false }); // => false
Parameters:
Name | Type | Description |
---|---|---|
defaultValue |
* | The default value |
lens |
function | Van Laarhoven lens |
data |
* | The data structure |
Returns:
"view" or defaultValue
- Type
- *
(static) weave(fn, config) → {function}
- Source:
- Since:
- Signature:
-
(*... -> *) -> * -> (*... -> *)
- Category:
-
- Function
Weaves a configuration into function returning the runnable monad like Reader
or Free
.
This allows us to pre-bind the configuration in advance and use the weaved function
without need to explicitly pass the configuration on every call.
Example
const { Reader: reader } = require('monet');
const log = value => reader(
config => config.log(value)
);
// no weaving
log('test').run(console); //=> prints 'test'
// weaving
const wlog = RA.weave(log, console);
wlog('test'); //=> prints 'test'
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | The function to weave |
config |
* | The configuration to weave into fn |
Returns:
Auto-curried weaved function
- Type
- function
(static) weaveLazy(fn, configAccessor) → {function}
- Source:
- Since:
- Signature:
-
(*... -> *) -> (* -> *) -> (*... -> *)
- Category:
-
- Function
Weaves a configuration into function returning the runnable monad like Reader
or Free
.
This allows us to pre-bind the configuration in advance and use the weaved function
without need to explicitly pass the configuration on every call.
Example
const { Reader: reader } = require('monet');
const log = value => reader(
config => config.log(value)
);
const consoleAccessor = R.always(console);
// no weaving
log('test').run(console); //=> prints 'test'
// weaving
const wlog = RA.weaveLazy(log, consoleAccessor);
wlog('test'); //=> prints 'test'
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | The function to weave |
configAccessor |
function | The function that returns the configuration object |
Returns:
Auto-curried weaved function
- Type
- function
(static) Y(le) → {function}
- Source:
- Since:
- Signature:
-
(a, ... -> b -> b) -> (a, ... -> b)
- Category:
-
- Function
- See also:
Y-combinator
The Y combinator is an interesting function which only works with functional languages, showing how recursion can still be done even without any variable or function declarations, only functions and parameters
Example
const makeFact = givenFact => (n) => {
if (n < 2) { return 1 }
return n * givenFact(n - 1);
};
const factorial = RA.Y(makeFact);
factorial(5); //=> 120
Parameters:
Name | Type | Description |
---|---|---|
le |
function | Recursive function maker |
Returns:
- Type
- function
(static) zipObjWith(fn, keys, values) → {Object}
- Source:
- Since:
- Signature:
-
(b, a) -> [k, v] -> [a] -> [b] -> { k: v }
- Category:
-
- Object
- See also:
Creates a new object out of a list of keys and a list of values by applying the function to each equally-positioned pair in the lists. Key/value pairing is truncated to the length of the shorter of the two lists.
Example
RA.zipObjWith((value, key) => [key, `${key}${value + 1}`]), ['a', 'b', 'c'], [1, 2, 3]);
// => { a: 'a2', b: 'b3', c: 'c4' }
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | The function to transform each value-key pair |
keys |
Array | Array to transform into the properties on the output object |
values |
Array | Array to transform into the values on the output object |
Returns:
The object made by pairing up and transforming same-indexed elements of keys
and values
.
- Type
- Object