Checks if the given object is present and it is not empty (contains at least one entry).
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
(
fs: ((...xs: any[]) => any)[]
) => (...xs: any[]) => object
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.
Questions
- How to get an empty object?
TypeScript source • JavaScript source
Lists key-value pairs (entries) present in the given object.
Type signature
{
<T>(
o:
| {
[s: string]: T;
}
| ArrayLike<T>
): [string, T][];
(o: {}): [string, any][];
}
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: any, b: any) => boolean
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
(
f: (value: any, key: string, context: object) => boolean
) => (xs: object) => 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
(
f: (value: any, key: string, context: object) => boolean
) => (xs: object) => object
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
(
predicate: (value: any, key: string, context: object) => boolean
) => (xs: object) => any
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
(
predicate: (value: any, key: string, context: object) => boolean
) => (xs: object) => any
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
(
predicate: (value: any, key: string, context: object) => boolean
) => (xs: object) => any
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.
Questions
- How to get the first value of an object?
TypeScript source • JavaScript source
Flat maps the values of the given object.
Type signature
(
f: (value: any, key: string, context: object) => any
) => (xs: object) => any[]
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
(entries: [string, any][]) => object
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: any) => string) => (xs: any[]) => object
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?: any) => any
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 number of entries within the given object.
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
(
f: (value: any, key: string, context: object) => any
) => (xs: object) => object
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
(
f: (value: any, key: string, context: object) => any
) => (xs: object) => [string, any][]
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
(
f: (value: any, key: string, context: object) => any
) => (xs: object) => object
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
(
f: (value: any, key: string, context: object) => any
) => (xs: object) => any[]
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: {
[index: string]: any;
},
b: object
) => object
Questions
- How to merge two objects together?
- How to deeply merge two objects?
TypeScript source • JavaScript source
Checks if the given object is empty.
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
(
f: (value: any, key: string, context: object) => boolean
) => (xs: object) => 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
(
f: (a: any, b: any) => number
) => (xs: object) => object
Examples
sort({
a: 3,
b: 2,
c: 3,
d: -7,
e: 13,
f: 0,
g: 8,
});
Try in REPL
TypeScript source • JavaScript source