Checks if the given object is present and it is not empty (contains at least one entry).
Type signature
<T>(xs?: GenericObject<T>) => boolean
Questions
- 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?
TypeScript source • JavaScript source
Applies the given parameters to the given dictionary of functions.
Type signature
<T>(fs: {
[index: string]: (...xs: T[]) => T;
}) => (...xs: T[]) => GenericObject<T>
Examples
const lower = (text) =>
text.toLowerCase();
const upper = (text) =>
text.toUpperCase();
apply({ lower, upper })("TeSt");
Try in REPL
Questions
- How to apply a value over an object of functions?
TypeScript source • JavaScript source
Empty object.
Type signature
GenericObject<unknown>;
export default empty
Questions
- How to get an empty object?
TypeScript source • JavaScript source
Lists key-value pairs (entries) present in the given object.
Questions
- How to get entries of an object?
- How to get an array of key-value pairs of an object?
TypeScript source • JavaScript source
Creates a 1 to 1 mapping of the given values as an object.
Type signature
(...xs: string[]) => object
Questions
- How to create an object of the same keys and values?
TypeScript source • JavaScript source
Checks if two objects are deeply equal.
Type signature
(a: unknown, b: unknown) => boolean;
export default equalsDeep
Questions
- How to check if two objects are equal?
- How to check deep object equality?
TypeScript source • JavaScript source
Test if every element passes the given predicate.
Type signature
<T>(f: (value: T, key: string, context: object) => boolean) => (xs: GenericObject<T>) => boolean
Examples
every((x) => x >= 0)({
x: 5,
y: 3,
z: 0,
});
Try in REPL
every((x) => x > 0)({
x: 5,
y: 3,
z: 0,
});
Try in REPL
Questions
- How to check if every entry in an object passes a given predicate?
TypeScript source • JavaScript source
Filters the given object with the given predicate.
Type signature
<T>(f: (value: T, key: string, context: object) => boolean) => (xs: GenericObject<T>) => GenericObject<T>
Examples
filter((x) => x % 2 !== 0)({
a: 1,
b: 2,
c: 3,
});
Try in REPL
TypeScript source • JavaScript source
Searches the given object by the given predicate and returns the found value or undefined.
Type signature
<T>(predicate: (value: T, key: string, context: object) => boolean) => (xs: GenericObject<T>) => T | undefined
Examples
find(({ x }) => x % 2 === 0)({
a: { x: 1 },
b: { x: 2 },
c: { x: 3 },
});
Try in REPL
Questions
- How to find the value of an object by a predicate function?
TypeScript source • JavaScript source
Searches the given object by the given predicate and returns the found entry or undefined.
Type signature
<T>(predicate: (value: T, key: string, context: GenericObject<T>) => boolean) => (xs: GenericObject<T>) => [string, T] | undefined
Examples
findEntry(({ x }) => x % 2 === 0)({
a: { x: 1 },
b: { x: 2 },
c: { x: 3 },
});
Try in REPL
Questions
- How to find an entry of an object by a predicate function?
TypeScript source • JavaScript source
Searches the given object by the given predicate and returns the found key or undefined.
Type signature
<T>(predicate: (value: T, key: string, context: object) => boolean) => (xs: GenericObject<T>) => string | undefined
Examples
findKey(({ x }) => x % 2 === 0)({
a: { x: 1 },
b: { x: 2 },
c: { x: 3 },
});
Try in REPL
Questions
- How to find a key of an object by a predicate function?
TypeScript source • JavaScript source
Returns the first value in the given object. Follows the default object iteration order.
Type signature
<T>(xs: GenericObject<T>) => T | undefined
Questions
- How to get the first value of an object?
TypeScript source • JavaScript source
Flat maps the values of the given object.
Type signature
<T, TResult>(f: (value: T, key: string, context: GenericObject<T>) => TResult[]) => (xs: GenericObject<T>) => TResult[]
Examples
flatMapValues((x) => [x, x * 2])({
a: 1,
b: 2,
c: 3,
});
Try in REPL
Questions
- How to flat map an object?
TypeScript source • JavaScript source
Creates an object from an array of key-value pairs (entries).
Type signature
<T>(entries: [string, T][]) => Result<T>
Examples
fromEntries([
["a", 1],
["b", 2],
["c", 3],
]);
Try in REPL
Questions
- How to create an object from an array of key-value pairs?
- How to create an object from an array of entries?
TypeScript source • JavaScript source
Groups the given array of values by the given key selector.
Type signature
(selector: (x: unknown) => string) => (xs: unknown[]) => Result
Examples
groupBy((x) =>
x % 2 == 0 ? "even" : "odd",
)([1, 2, 3, 4, 5, 6, 7]);
Try in REPL
Questions
- How to group an array by a key function?
TypeScript source • JavaScript source
Checks if the given key is present in the object.
Type signature
(key: string) => (xs?: unknown) => boolean
Examples
hasKey("c")({ a: 1, b: 2, c: 3 });
Try in REPL
Questions
- How to check if an object contains a given key?
TypeScript source • JavaScript source
Returns the last value in the given object. Follows the default object iteration order.
Type signature
<T>(xs: GenericObject<T>) => T | undefined
Questions
- How to get the last value of an object?
TypeScript source • JavaScript source
Returns the number of entries within the given object.
Type signature
<T>(xs: GenericObject<T>) => number
Questions
- How to check how many entries are in an object?
TypeScript source • JavaScript source
Maps the given object with the given function.
Type signature
<T, TResult>(f: (value: T, key: string, context: object) => TResult) => (xs: GenericObject<T>) => GenericObject<TResult>
Examples
map((x) => x ** 2)({
a: 1,
b: 2,
c: 3,
});
Try in REPL
Questions
- How to map an object?
- How to transform an object?
TypeScript source • JavaScript source
Maps entries of the given object.
Type signature
<T, TResult>(f: (value: T, key: string, context: object) => TResult) => (xs: GenericObject<T>) => [string, TResult][]
Examples
mapEntries((x) => x ** 2)({
a: 1,
b: 2,
c: 3,
});
Try in REPL
Questions
- How to map object entries?
TypeScript source • JavaScript source
Transforms the object keys with the given function.
Type signature
<T>(f: (value: T, key: string, context: object) => string) => (xs: GenericObject<T>) => GenericObject<T>
Examples
mapKeys((_, key) =>
key.toUpperCase(),
)({ a: 1, b: 2, c: 3 });
Try in REPL
Questions
- How to map object keys?
- How to transform object keys?
TypeScript source • JavaScript source
Maps and returns an array of transformed object values.
Type signature
<T, TResult>(f: (value: T, key: string, context: object) => TResult) => (xs: GenericObject<T>) => TResult[]
Examples
mapValues((x) => x ** 2)({
a: 1,
b: 2,
c: 3,
});
Try in REPL
Questions
- How to map object values?
TypeScript source • JavaScript source
Merges two objects deeply.
Type signature
(a: GenericObject, b: GenericObject) => GenericObject;
export default merge
Examples
merge({ a: 1, b: 3 }, {});
Try in REPL
merge({ a: 1, b: 3 }, { b: 7 });
Try in REPL
merge(
{ a: 1, b: 3 },
{ b: { d: 8 } },
);
Try in REPL
merge(
{ a: 1, b: { c: 3 } },
{ b: { d: 8 } },
);
Try in REPL
Questions
- How to merge two objects together?
- How to deeply merge two objects?
TypeScript source • JavaScript source
Checks if the given object is empty.
Type signature
<T>(xs?: GenericObject<T>) => boolean
Questions
- How to check if an object is empty?
- How to check if an object is null or undefined?
TypeScript source • JavaScript source
Test if any element passes the given predicate.
Type signature
<T>(f: (value: T, key: string, context: object) => boolean) => (xs: GenericObject<T>) => boolean
Examples
some((x) => x >= 4)({
x: 5,
y: 3,
z: 0,
});
Try in REPL
some((x) => x < 0)({
x: 5,
y: 3,
z: 0,
});
Try in REPL
Questions
- How to check if any entry in an object passes a given predicate?
TypeScript source • JavaScript source
Sorts the given object by a comparator.
Type signature
<T>(f: (a: T, b: T) => number) => (xs: GenericObject<T>) => GenericObject<T>
Examples
sort({
a: 3,
b: 2,
c: 3,
d: -7,
e: 13,
f: 0,
g: 8,
});
Try in REPL
TypeScript source • JavaScript source