object

Checks if the given object is present and it is not empty (contains at least one entry).

Type signature

(xs?: object) => boolean

Examples

any({ a: 1, b: 2, c: 3 });
// ⇒ true
Try in REPL
any({});
// ⇒ false
Try in REPL
any(null);
// ⇒ false
Try in REPL
any(undefined);
// ⇒ false
Try in REPL

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 sourceJavaScript 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");
// ⇒ { lower: "test", upper: "TEST" }
Try in REPL

Questions

  • How to apply a value over an object of functions?

TypeScript sourceJavaScript source

Empty object.

Type signature

{}

Examples

empty;
// ⇒ {}
Try in REPL

Questions

  • How to get an empty object?

TypeScript sourceJavaScript 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][];
}

Examples

entries({ a: 1, b: 2, c: 3 });
// ⇒ [["a", 1], ["b", 2], ["c", 3]]
Try in REPL

Questions

  • How to get entries of an object?
  • How to get an array of key-value pairs of an object?

TypeScript sourceJavaScript source

Creates a 1 to 1 mapping of the given values as an object.

Type signature

(...xs: string[]) => object

Examples

enumerable("TEST", "X", "Y");
// ⇒ { TEST: 'TEST', X: 'X', Y: 'Y' }
Try in REPL

Questions

  • How to create an object of the same keys and values?

TypeScript sourceJavaScript source

Checks if two objects are deeply equal.

Type signature

(a: any, b: any) => boolean

Examples

equals({ a: 1 }, { a: 1 });
// ⇒ true
Try in REPL
equals(
  { b: [1, 2] },
  { b: [1, 2] }
);
// ⇒ true
Try in REPL

Questions

  • How to check if two objects are equal?
  • How to check deep object equality?

TypeScript sourceJavaScript 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,
});
// ⇒ true
Try in REPL
every((x) => x > 0)({
  x: 5,
  y: 3,
  z: 0,
});
// ⇒ false
Try in REPL

Questions

  • How to check if every entry in an object passes a given predicate?

TypeScript sourceJavaScript 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,
});
// ⇒ { a: 1, c: 3 }
Try in REPL

Questions

  • How to filter an object?

TypeScript sourceJavaScript 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 },
});
// ⇒ { x: 2 }
Try in REPL

Questions

  • How to find the value of an object by a predicate function?

TypeScript sourceJavaScript 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 },
});
// ⇒ ["b", { x: 2 }]
Try in REPL

Questions

  • How to find an entry of an object by a predicate function?

TypeScript sourceJavaScript 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 },
});
// ⇒ "b"
Try in REPL

Questions

  • How to find a key of an object by a predicate function?

TypeScript sourceJavaScript source

Returns the first value in the given object. Follows the default object iteration order.

Type signature

(xs: object) => any

Examples

first({ a: 1, b: 2, c: 3 });
// ⇒ 1
Try in REPL

Questions

  • How to get the first value of an object?

TypeScript sourceJavaScript 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,
});
// ⇒ [1, 2, 2, 4, 3, 6]
Try in REPL

Questions

  • How to flat map an object?

TypeScript sourceJavaScript 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],
]);
// ⇒ { 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 sourceJavaScript 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]);
// ⇒ { even: [2, 4, 6], odd: [1, 3, 5, 7] }
Try in REPL

Questions

  • How to group an array by a key function?

TypeScript sourceJavaScript 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 });
// ⇒ true
Try in REPL

Questions

  • How to check if an object contains a given key?

TypeScript sourceJavaScript source

Returns the number of entries within the given object.

Type signature

(xs: object) => number

Examples

length({ a: 1, b: 2, c: 3 });
// ⇒ 3
Try in REPL

Questions

  • How to check how many entries are in an object?

TypeScript sourceJavaScript 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,
});
// ⇒ { a: 1, b: 4, c: 9 }
Try in REPL

Questions

  • How to map an object?
  • How to transform an object?

TypeScript sourceJavaScript 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,
});
// ⇒ [["a", 1], ["b", 4], ["c", 9]]
Try in REPL

Questions

  • How to map object entries?

TypeScript sourceJavaScript 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 });
// ⇒ { A: 1, B: 2, C: 3 }
Try in REPL

Questions

  • How to map object keys?
  • How to transform object keys?

TypeScript sourceJavaScript 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,
});
// ⇒ [1, 4, 9]
Try in REPL

Questions

  • How to map object values?

TypeScript sourceJavaScript source

Merges two objects deeply.

Type signature

(
  a: {
    [index: string]: any;
  },
  b: object
) => object

Examples

merge({ a: 1, b: 3 }, {});
// ⇒ { a: 1, b: 3 }
Try in REPL
merge({ a: 1, b: 3 }, { b: 7 });
// ⇒ { a: 1, b: 7 }
Try in REPL
merge(
  { a: 1, b: 3 },
  { b: { d: 8 } }
);
// ⇒ { a: 1, b: { d: 8 } }
Try in REPL
merge(
  { a: 1, b: { c: 3 } },
  { b: { d: 8 } }
);
// ⇒ { a: 1, b: { c: 3, d: 8 } }
Try in REPL

Questions

  • How to merge two objects together?
  • How to deeply merge two objects?

TypeScript sourceJavaScript source

Checks if the given object is empty.

Type signature

(xs?: object) => boolean

Examples

none({});
// ⇒ true
Try in REPL
none(null);
// ⇒ true
Try in REPL
none({ a: 1 });
// ⇒ false
Try in REPL

Questions

  • How to check if an object is empty?
  • How to check if an object is null or undefined?

TypeScript sourceJavaScript 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,
});
// ⇒ true
Try in REPL
some((x) => x < 0)({
  x: 5,
  y: 3,
  z: 0,
});
// ⇒ false
Try in REPL

Questions

  • How to check if any entry in an object passes a given predicate?

TypeScript sourceJavaScript 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,
});
// ⇒ {"d": -7,"f": 0,"b": 2,"a": 3,"c": 3,"g": 8,"e": 13}
Try in REPL

Questions

  • How to sort an object?

TypeScript sourceJavaScript source