Classes
Methods
(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 than 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.
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) 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) curryRight(fn) → {function}
- Source:
- Since:
- Signature:
-
Number -> (* -> 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) 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) hasPath(path, obj) → {Boolean}
- Source:
- Since:
- 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) 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) 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) 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) 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) 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) 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) isNegative(val) → {Boolean}
- Source:
- Since:
- Signature:
-
* -> Boolean
- Category:
-
- Type
- See also:
Checks if value is a negative Number
primitive or object.
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) 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) 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:
-
- Type
- 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) 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) 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) 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.
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) 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) 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) 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) 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) 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(R.equals(true), R.lensIndex(0), [false, true, 1]); // => true
RA.lensNotSatisfy(R.equals(true), R.lensIndex(1), [false, true, 1]); // => false
RA.lensNotSatisfy(R.equals(true), 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(R.equals(true), R.lensIndex(0), [false, true, 1]); // => false
RA.lensSatisfies(R.equals(true), R.lensIndex(1), [false, true, 1]); // => true
RA.lensSatisfies(R.equals(true), 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) 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 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.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 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) 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:
- Signature:
-
{k: v} -> {k: v} -> {k: v}
- Aliases:
-
- resetToDefault, defaults
- 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) noop() → {undefined}
A function that performs no operations.
Example
RA.noop(); //=> undefined
RA.noop(1, 2, 3); //=> undefined
Returns:
- Type
- undefined
(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) 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.
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) 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) 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) 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) 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) 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