Checks if the given object is present and it is not empty (contains at least one entry).
<T>(xs?: GenericObject<T>) => booleanany({ a: 1, b: 2, c: 3 });
// ⇒ trueany({ });
// ⇒ falseany(null);
// ⇒ falseany(undefined);
// ⇒ false- How to check if an object is not empty?
- How to check if an object contains some values?
- How to check if an object is not null or undefined?
Applies the given parameters to the given dictionary of functions.
<T>(fs: {
[index: string]: (...xs: T[]) => T;
}) => (...xs: T[]) => GenericObject<T>const lower = text => text.toLowerCase();
const upper = text => text.toUpperCase();
apply({ lower, upper })("TeSt");
// ⇒ { lower: "test", upper: "TEST" }- How to apply a value over an object of functions?
Empty object.
GenericObject<unknown>;
export default emptyempty;
// ⇒ {}- How to get an empty object?
Lists key-value pairs (entries) present in the given object.
ObjectEntriesentries({ a: 1, b: 2, c: 3 });
// ⇒ [["a", 1], ["b", 2], ["c", 3]]- How to get entries of an object?
- How to get an array of key-value pairs of an object?
Creates a 1 to 1 mapping of the given values as an object.
(...xs: string[]) => objectenumerable('TEST', 'X', 'Y');
// ⇒ { TEST: 'TEST', X: 'X', Y: 'Y' }- How to create an object of the same keys and values?
Checks if two objects are deeply equal.
(a: unknown, b: unknown) => boolean;
export default equalsDeepequals({ a: 1 }, { a: 1 });
// ⇒ trueequals({ b: [1, 2] }, { b: [1, 2] });
// ⇒ true- How to check if two objects are equal?
- How to check deep object equality?
Test if every element passes the given predicate.
<T>(f: (value: T, key: string, context: object) => boolean) => (xs: GenericObject<T>) => booleanevery(x => x >= 0)({ x: 5, y: 3, z: 0 });
// ⇒ trueevery(x => x > 0)({ x: 5, y: 3, z: 0 });
// ⇒ false- How to check if every entry in an object passes a given predicate?
Filters the given object with the given predicate.
<T>(f: (value: T, key: string, context: object) => boolean) => (xs: GenericObject<T>) => GenericObject<T>filter(x => x % 2 !== 0)({ a: 1, b: 2, c: 3 });
// ⇒ { a: 1, c: 3 }- How to filter an object?
Searches the given object by the given predicate and returns the found value or undefined.
<T>(predicate: (value: T, key: string, context: object) => boolean) => (xs: GenericObject<T>) => T | undefinedfind(({ x }) => x % 2 === 0)({ a: { x: 1 }, b: { x: 2 }, c: { x: 3 } });
// ⇒ { x: 2 }- How to find the value of an object by a predicate function?
Searches the given object by the given predicate and returns the found entry or undefined.
<T>(predicate: (value: T, key: string, context: GenericObject<T>) => boolean) => (xs: GenericObject<T>) => [string, T] | undefinedfindEntry(({ x }) => x % 2 === 0)({ a: { x: 1 }, b: { x: 2 }, c: { x: 3 } });
// ⇒ ["b", { x: 2 }]- How to find an entry of an object by a predicate function?
Searches the given object by the given predicate and returns the found key or undefined.
<T>(predicate: (value: T, key: string, context: object) => boolean) => (xs: GenericObject<T>) => string | undefinedfindKey(({ x }) => x % 2 === 0)({ a: { x: 1 }, b: { x: 2 }, c: { x: 3 } });
// ⇒ "b"- How to find a key of an object by a predicate function?
Returns the first value in the given object. Follows the default object iteration order.
<T>(xs: GenericObject<T>) => T | undefinedfirst({ a: 1, b: 2, c: 3 });
// ⇒ 1- How to get the first value of an object?
Flat maps the values of the given object.
<T, TResult>(f: (value: T, key: string, context: GenericObject<T>) => TResult[]) => (xs: GenericObject<T>) => TResult[]flatMapValues(x => [x, x * 2])({ a: 1, b: 2, c: 3 });
// ⇒ [1, 2, 2, 4, 3, 6]- How to flat map an object?
Creates an object from an array of key-value pairs (entries).
<T>(entries: [string, T][]) => Result<T>fromEntries([["a", 1], ["b", 2], ["c", 3]]);
// ⇒ { a: 1, b: 2, c: 3 }- How to create an object from an array of key-value pairs?
- How to create an object from an array of entries?
Groups the given array of values by the given key selector.
(selector: (x: unknown) => string) => (xs: unknown[]) => ResultgroupBy(x => x % 2 == 0 ? "even" : "odd")([1, 2, 3, 4, 5, 6, 7]);
// ⇒ { even: [2, 4, 6], odd: [1, 3, 5, 7] }- How to group an array by a key function?
Checks if the given key is present in the object.
(key: string) => (xs?: unknown) => booleanhasKey("c")({ a: 1, b: 2, c: 3 });
// ⇒ true- How to check if an object contains a given key?
Returns the last value in the given object. Follows the default object iteration order.
<T>(xs: GenericObject<T>) => T | undefinedlast({ a: 1, b: 2, c: 3 });
// ⇒ 3- How to get the last value of an object?
Returns the number of entries within the given object.
<T>(xs: GenericObject<T>) => numberlength({ a: 1, b: 2, c: 3 });
// ⇒ 3- How to check how many entries are in an object?
Maps the given object with the given function.
<T, TResult>(f: (value: T, key: string, context: object) => TResult) => (xs: GenericObject<T>) => GenericObject<TResult>map(x => x ** 2)({ a: 1, b: 2, c: 3 });
// ⇒ { a: 1, b: 4, c: 9 }- How to map an object?
- How to transform an object?
Maps entries of the given object.
<T, TResult>(f: (value: T, key: string, context: object) => TResult) => (xs: GenericObject<T>) => [string, TResult][]mapEntries(x => x ** 2)({ a: 1, b: 2, c: 3 });
// ⇒ [["a", 1], ["b", 4], ["c", 9]]- How to map object entries?
Transforms the object keys with the given function.
<T>(f: (value: T, key: string, context: object) => string) => (xs: GenericObject<T>) => GenericObject<T>mapKeys((_, key) => key.toUpperCase())({ a: 1, b: 2, c: 3 });
// ⇒ { A: 1, B: 2, C: 3 }- How to map object keys?
- How to transform object keys?
Maps and returns an array of transformed object values.
<T, TResult>(f: (value: T, key: string, context: object) => TResult) => (xs: GenericObject<T>) => TResult[]mapValues(x => x ** 2)({ a: 1, b: 2, c: 3 });
// ⇒ [1, 4, 9]- How to map object values?
Merges two objects deeply.
(a: GenericObject, b: GenericObject) => GenericObject;
export default mergemerge({ a: 1, b: 3 }, {});
// ⇒ { a: 1, b: 3 }merge({ a: 1, b: 3 }, { b: 7 });
// ⇒ { a: 1, b: 7 }merge({ a: 1, b: 3 }, { b: { d: 8 } });
// ⇒ { a: 1, b: { d: 8 } }merge({ a: 1, b: { c: 3 } }, { b: { d: 8 } });
// ⇒ { a: 1, b: { c: 3, d: 8 } }- How to merge two objects together?
- How to deeply merge two objects?
Checks if the given object is empty.
<T>(xs?: GenericObject<T>) => booleannone({});
// ⇒ truenone(null);
// ⇒ truenone({ a: 1 });
// ⇒ false- How to check if an object is empty?
- How to check if an object is null or undefined?
Test if any element passes the given predicate.
<T>(f: (value: T, key: string, context: object) => boolean) => (xs: GenericObject<T>) => booleansome(x => x >= 4)({ x: 5, y: 3, z: 0 });
// ⇒ truesome(x => x < 0)({ x: 5, y: 3, z: 0 });
// ⇒ false- How to check if any entry in an object passes a given predicate?
Sorts the given object by a comparator.
<T>(f: (a: T, b: T) => number) => (xs: GenericObject<T>) => GenericObject<T>sort({ a: 3, b: 2, c: 3, d: -7, e: 13, f: 0, g: 8 });
// ⇒ {"d": -7,"f": 0,"b": 2,"a": 3,"c": 3,"g": 8,"e": 13}- How to sort an object?