extra-map

  • Version 3.1.15
  • Published
  • 80.6 kB
  • No dependencies
  • MIT license

Install

npm i extra-map
yarn add extra-map
pnpm add extra-map

Overview

A group of functions for working with Maps.

Index

Functions

function cartesianProduct

cartesianProduct: <K, V, W = Map<K, V>>(
xs: Map<K, V>[],
fm?: MapFunction<number, Map<K, V>, Map<K, V> | W> | null
) => IterableIterator<Map<K, V> | W>;
  • List cartesian product of maps. [📘](https://github.com/nodef/extra-map/wiki/cartesianProduct)

    Parameter xs

    maps

    Parameter fm

    map function (vs, i)

    Returns

    x₀ × x₁ × ... = {{[k₀, v₀], [k₁, v₁], ...} | [k₀, v₀] ∈ x₀, [k₁, v₁] ∈ x₁, ...]}

function chunk

chunk: <K, V>(x: Map<K, V>, n?: number, s?: number) => Map<K, V>[];
  • Break map into chunks of given size. [📘](https://github.com/nodef/extra-map/wiki/chunk)

    Parameter x

    a map

    Parameter n

    chunk size [1]

    Parameter s

    chunk step [n]

    Returns

    [x[0..n], x[s..s+n], x[2s..2s+n], ...]

function compare

compare: <K, V, W = V>(
x: Map<K, V>,
y: Map<K, V>,
fc?: CompareFunction<V | W> | null,
fm?: MapFunction<K, V, V | W> | null
) => number;
  • Compare two maps. [📘](https://github.com/nodef/extra-map/wiki/compare)

    Parameter x

    a map

    Parameter y

    another map

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, k, x)

    Returns

    x=y: 0, otherwise: -ve/+ve

function concat

concat: <K, V>(...xs: Entries<K, V>[]) => Map<K, V>;
  • Append entries from maps, preferring last. [📘](https://github.com/nodef/extra-map/wiki/concat)

    Parameter xs

    maps

    Returns

    x₀ ∪ x₁ ∪ ... | [x₀, x₁, ...] = xs

function concat$

concat$: <K, V>(x: Map<K, V>, ...ys: Entries<K, V>[]) => Map<K, V>;
  • Append entries from maps, preferring last. [📘](https://github.com/nodef/extra-map/wiki/concat$)

    Parameter x

    a map (updated)

    Parameter ys

    other maps

    Returns

    x = x ∪ y₀ ∪ y₁ ∪ ... | [y₀, y₁, ...] = ys

function count

count: <K, V>(x: Map<K, V>, ft: TestFunction<K, V>) => number;
  • Count values which satisfy a test. [📘](https://github.com/nodef/extra-map/wiki/count)

    Parameter x

    a map

    Parameter ft

    test function (v, k, x)

    Returns

    Σtᵢ | tᵢ = 1 if ft(vᵢ) else 0; [kᵢ, vᵢ] ∈ x

function countAs

countAs: <K, V, W = V>(
x: Map<K, V>,
fm?: MapFunction<K, V, V | W> | null
) => Map<V | W, number>;
  • Count occurrences of values. [📘](https://github.com/nodef/extra-map/wiki/countAs)

    Parameter x

    a map

    Parameter fm

    map function (v, k, x)

    Returns

    Map {value ⇒ count}

function difference

difference: <K, V>(x: Entries<K, V>, y: Entries<K, V>) => Map<K, V>;
  • Obtain entries not present in another map. [📘](https://github.com/nodef/extra-map/wiki/difference)

    Parameter x

    a map

    Parameter y

    another map

    Returns

    x - y = {[kᵢ, vᵢ] | [kᵢ, vᵢ] ∈ x, [kᵢ, *] ∉ y}

function difference$

difference$: <K, V>(x: Map<K, V>, y: Entries<K, V>) => Map<K, V>;
  • Obtain entries not present in another map. [📘](https://github.com/nodef/extra-map/wiki/difference$)

    Parameter x

    a map (updated)

    Parameter y

    another map

    Returns

    x = x - y = {[kᵢ, vᵢ] | [kᵢ, vᵢ] ∈ x, [kᵢ, *] ∉ y}

function drop

drop: <K, V>(x: Map<K, V>, n?: number) => Map<K, V>;
  • Remove first n entries (default order). [📘](https://github.com/nodef/extra-map/wiki/drop)

    Parameter x

    a map

    Parameter n

    number of entries [1]

    Returns

    {[kₙ, vₙ], [kₙ₊₁, vₙ₊₁], ...} | [kᵢ, vᵢ] ∈ x and |{[kₙ, vₙ], [kₙ₊₁, vₙ₊₁], ...}| ≤ max(|x| - n, 0)

function drop$

drop$: <K, V>(x: Map<K, V>, n?: number) => Map<K, V>;
  • Remove first n entries (default order). [📘](https://github.com/nodef/extra-map/wiki/drop$)

    Parameter x

    a map (updated)

    Parameter n

    number of entries [1]

    Returns

    x = {[kₙ, vₙ], [kₙ₊₁, vₙ₊₁], ...} | [kᵢ, vᵢ] ∈ x and |{[kₙ, vₙ], [kₙ₊₁, vₙ₊₁], ...}| ≤ max(|x| - n, 0)

function entries

entries: <K, V>(x: Map<K, V>) => IterableIterator<[K, V]>;
  • List all key-value pairs. [📘](https://github.com/nodef/extra-map/wiki/entries)

    Parameter x

    a map

    Returns

    [k₀, v₀], [k₁, v₁], ... | [kᵢ, vᵢ] ∈ x

function entry

entry: <K, V>(x: Entries<K, V>, fr?: ReadFunction<number>) => [K, V];
  • Pick an arbitrary entry. [📘](https://github.com/nodef/extra-map/wiki/randomEntry)

    Parameter x

    a map

    Parameter fr

    random number generator ([0, 1))

    Returns

    [kᵢ, vᵢ] | [kᵢ, vᵢ] ∈ x

function every

every: <K, V>(x: Map<K, V>, ft: TestFunction<K, V>) => boolean;
  • Check if all values satisfy a test. [📘](https://github.com/nodef/extra-map/wiki/every)

    Parameter x

    a map

    Parameter ft

    test function (v, k, x)

    Returns

    true if ft(vᵢ) = true for all [kᵢ, vᵢ] ∈ x

function filter

filter: <K, V>(x: Map<K, V>, ft: TestFunction<K, V>) => Map<K, V>;
  • Keep entries which pass a test. [📘](https://github.com/nodef/extra-map/wiki/filter)

    Parameter x

    a map

    Parameter ft

    test function (v, k, x)

    Returns

    {[k₀, v₀], [k₁, v₁], ...} | ft(vᵢ) = true; [kᵢ, vᵢ] ∈ x

function filter$

filter$: <K, V>(x: Map<K, V>, ft: TestFunction<K, V>) => Map<K, V>;
  • Keep entries which pass a test. [📘](https://github.com/nodef/extra-map/wiki/filter$)

    Parameter x

    an map (updated)

    Parameter ft

    test function (v, k, x)

    Returns

    x = {[k₀, v₀], [k₁, v₁], ...} | ft(vᵢ) = true; [kᵢ, vᵢ] ∈ x

function filterAt

filterAt: <K, V>(x: Map<K, V>, ks: K[]) => Map<K, V>;
  • Keep values at given keys. [📘](https://github.com/nodef/extra-map/wiki/filterAt)

    Parameter x

    a map

    Parameter ks

    keys

    Returns

    {[k₀, v₀], [k₁, v₁], ...} | kᵢ ∈ ks; [kᵢ, vᵢ] ∈ x

function filterAt$

filterAt$: <K, V>(x: Map<K, V>, ks: K[]) => Map<K, V>;
  • Keep values at given keys. [📘](https://github.com/nodef/extra-map/wiki/filterAt$)

    Parameter x

    a map (updated)

    Parameter ks

    keys

    Returns

    x = {[k₀, v₀], [k₁, v₁], ...} | kᵢ ∈ ks; [kᵢ, vᵢ] ∈ x

function find

find: <K, V>(x: Map<K, V>, ft: TestFunction<K, V>) => V;
  • Find first value passing a test (default order). [📘](https://github.com/nodef/extra-map/wiki/find)

    Parameter x

    a map

    Parameter ft

    test function (v, k, x)

    Returns

    first v | ft(v) = true; [k, v] ∈ x

function findAll

findAll: <K, V>(x: Map<K, V>, ft: TestFunction<K, V>) => V[];
  • Find values passing a test. [📘](https://github.com/nodef/extra-map/wiki/findAll)

    Parameter x

    a map

    Parameter ft

    test function (v, k, x)

    Returns

    [v₀, v₁, ...] | ft(vᵢ) = true; [kᵢ, vᵢ] ∈ x

function flat

flat: <K>(
x: Map<K, any>,
n?: number,
fm?: MapFunction<K, any, any> | null,
ft?: TestFunction<K, any> | null
) => Map<K, any>;
  • Flatten nested map to given depth. [📘](https://github.com/nodef/extra-map/wiki/flat)

    Parameter x

    a nested map

    Parameter n

    maximum depth [-1 ⇒ all]

    Parameter fm

    map function (v, k, x)

    Parameter ft

    test function for flatten (v, k, x) [is]

    Returns

    flat map

function flatMap

flatMap: <K>(
x: Map<K, any>,
fm?: MapFunction<K, any, any> | null,
ft?: TestFunction<K, any> | null
) => Map<K, any>;
  • Flatten nested map, based on map function. [📘](https://github.com/nodef/extra-map/wiki/flatMap)

    Parameter x

    a nested map

    Parameter fm

    map function (v, k, x)

    Parameter ft

    test function for flatten (v, k, x) [is]

    Returns

    flat map

function forEach

forEach: <K, V>(x: Map<K, V>, fp: ProcessFunction<K, V>) => void;
  • Call a function for each value. [📘](https://github.com/nodef/extra-map/wiki/forEach)

    Parameter x

    a map

    Parameter fp

    process function (v, k, x)

function from

from: <K, V>(x: Entries<K, V>) => Map<K, V>;
  • Convert entries to map. [📘](https://github.com/nodef/extra-map/wiki/from)

    Parameter x

    entries

    Returns

    x as map

function from$

from$: <K, V>(x: Entries<K, V>) => Map<K, V>;
  • Convert entries to map. [📘](https://github.com/nodef/extra-map/wiki/from$)

    Parameter x

    entries (updateable is map!)

    Returns

    x as map

function fromEntries

fromEntries: <K, V>(x: Entries<K, V>) => Map<K, V>;
  • Convert entries to map. [📘](https://github.com/nodef/extra-map/wiki/from)

    Parameter x

    entries

    Returns

    x as map

function fromEntries$

fromEntries$: <K, V>(x: Entries<K, V>) => Map<K, V>;
  • Convert entries to map. [📘](https://github.com/nodef/extra-map/wiki/from$)

    Parameter x

    entries (updateable is map!)

    Returns

    x as map

function fromKeys

fromKeys: <K, V = K>(
x: Iterable<K>,
fm?: MapFunction$1<K, K | V> | null
) => Map<K, K | V>;
  • Create a map from keys. [📘](https://github.com/nodef/extra-map/wiki/fromKeys)

    Parameter x

    keys

    Parameter fm

    map function for values (v, i, x)

    Returns

    x as map

function fromLists

fromLists: <K, V>(x: Lists<K, V>) => Map<K, V>;
  • Convert lists to map. [📘](https://github.com/nodef/extra-map/wiki/fromLists)

    Parameter x

    lists, i.e. [keys, values]

    Returns

    x as map

function fromValues

fromValues: <V, K = V>(
x: Iterable<V>,
fm?: MapFunction$1<V, V | K> | null
) => Map<V | K, V>;
  • Create a map from values. [📘](https://github.com/nodef/extra-map/wiki/fromValues)

    Parameter x

    values

    Parameter fm

    map function for keys (v, i, x)

    Returns

    x as map

function get

get: <K, V>(x: Map<K, V>, k: K) => V;
  • Get value at key. [📘](https://github.com/nodef/extra-map/wiki/get)

    Parameter x

    a map

    Parameter k

    key

    Returns

    x[k]

function getAll

getAll: <K, V>(x: Map<K, V>, ks: K[]) => V[];
  • Get values at keys. [📘](https://github.com/nodef/extra-map/wiki/getAll)

    Parameter x

    a map

    Parameter ks

    keys

    Returns

    [x[k₀], x[k₁], ...] | [k₀, k₁, ...] = ks

function getPath

getPath: <K>(x: Map<K, any>, p: K[]) => any;
  • Get value at path in a nested map. [📘](https://github.com/nodef/extra-map/wiki/getPath)

    Parameter x

    a nested map

    Parameter p

    path

    Returns

    x[k₀][k₁][...] | [k₀, k₁, ...] = p

function has

has: <K, V>(x: Map<K, V>, k: K) => boolean;
  • Check if map has a key. [📘](https://github.com/nodef/extra-map/wiki/has)

    Parameter x

    a map

    Parameter k

    search key

    Returns

    [k, *] ∈ x?

function hasEntry

hasEntry: <K, V, W = V>(
x: Map<K, V>,
e: [K, V],
fc?: CompareFunction<V | W> | null,
fm?: MapFunction<K, V, V | W> | null
) => boolean;
  • Check if map has an entry. [📘](https://github.com/nodef/extra-map/wiki/hasEntry)

    Parameter x

    a map

    Parameter e

    search entry ([k, v])

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, k, x)

    Returns

    [k, v] ∈ x? | [k, v] = e

function hasKey

hasKey: <K, V>(x: Map<K, V>, k: K) => boolean;
  • Check if map has a key. [📘](https://github.com/nodef/extra-map/wiki/has)

    Parameter x

    a map

    Parameter k

    search key

    Returns

    [k, *] ∈ x?

function hasPath

hasPath: <K>(x: Map<K, any>, p: K[]) => boolean;
  • Check if nested map has a path. [📘](https://github.com/nodef/extra-map/wiki/hasPath)

    Parameter x

    a nested map

    Parameter p

    path

    Returns

    x[k₀][k₁][...] exists? | [k₀, k₁, ...] = p

function hasSubset

hasSubset: <K, V, W = V>(
x: Map<K, V>,
y: Map<K, V>,
fc?: CompareFunction<V | W> | null,
fm?: MapFunction<K, V, V | W> | null
) => boolean;
  • Check if map has a subset. [📘](https://github.com/nodef/extra-map/wiki/hasSubset)

    Parameter x

    a map

    Parameter y

    search subset

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, k, x)

    Returns

    y ⊆ x?

function hasValue

hasValue: <K, V, W = V>(
x: Map<K, V>,
v: V,
fc?: CompareFunction<V | W> | null,
fm?: MapFunction<K, V, V | W> | null
) => boolean;
  • Check if map has a value. [📘](https://github.com/nodef/extra-map/wiki/hasValue)

    Parameter x

    a map

    Parameter v

    search value

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, k, x)

    Returns

    [*, v] ∈ x?

head: <K, V>(x: Entries<K, V>, ed?: [K, V]) => [K, V];
  • Get first entry from map (default order). [📘](https://github.com/nodef/extra-map/wiki/head)

    Parameter x

    a map

    Parameter ed

    default entry

    Returns

    [k₀, v₀] if x ≠ Φ else ed | [k₀, v₀] ∈ x

function intersection

intersection: <K, V>(
x: Map<K, V>,
y: Entries<K, V>,
fc?: CombineFunction<V> | null
) => Map<K, V>;
  • Obtain entries present in both maps. [📘](https://github.com/nodef/extra-map/wiki/intersection)

    Parameter x

    a map

    Parameter y

    another map

    Parameter fc

    combine function (a, b)

    Returns

    x ∩ y = {[kᵢ, vᵢ] | [kᵢ, vᵢ] ∈ x and [kᵢ, vᵢ] ∈ y}

function intersection$

intersection$: <K, V>(
x: Map<K, V>,
y: Map<K, V>,
fc?: CombineFunction<V> | null
) => Map<K, V>;
  • Obtain entries present in both maps. [📘](https://github.com/nodef/extra-map/wiki/intersection$)

    Parameter x

    a map (updated)

    Parameter y

    another map

    Parameter fc

    combine function (a, b)

    Returns

    x = x ∩ y = {[kᵢ, vᵢ] | [kᵢ, vᵢ] ∈ x and [kᵢ, vᵢ] ∈ y}

function intersectionKeys

intersectionKeys: <K, V>(...xs: Map<K, V>[]) => Set<K>;
  • Obtain keys present in all maps. [📘](https://github.com/nodef/extra-map/wiki/intersectionKeys)

    Parameter xs

    maps

    Returns

    [k₀, k₁, ...] | [kᵢ, vᵢ] ∈ x₀ ∩ x₁, ...; [x₀, x₁, ...] = xs

function is

is: (v: any) => v is Map<any, any>;
  • Check if value is a map. [📘](https://github.com/nodef/extra-map/wiki/is)

    Parameter v

    value

    Returns

    v is a map?

function isDisjoint

isDisjoint: <K, V>(x: Map<K, V>, y: Entries<K, V>) => boolean;
  • Check if maps have no common keys. [📘](https://github.com/nodef/extra-map/wiki/isDisjoint)

    Parameter x

    a map

    Parameter y

    another map

    Returns

    x ∩ y = Φ?

function isEmpty

isEmpty: <K, V>(x: Map<K, V>) => boolean;
  • Check if a map is empty. [📘](https://github.com/nodef/extra-map/wiki/isEmpty)

    Parameter x

    a map

    Returns

    |x| = 0?

function isEqual

isEqual: <K, V, W = V>(
x: Map<K, V>,
y: Map<K, V>,
fc?: CompareFunction<V | W> | null,
fm?: MapFunction<K, V, V | W> | null
) => boolean;
  • Check if two maps are equal. [📘](https://github.com/nodef/extra-map/wiki/isEqual)

    Parameter x

    a map

    Parameter y

    another map

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, k, x)

    Returns

    x = y?

function join

join: <K, V>(x: Entries<K, V>, sep?: string, asc?: string) => string;
  • Join entries together into a string. [📘](https://github.com/nodef/extra-map/wiki/join)

    Parameter x

    a map

    Parameter sep

    separator [,]

    Parameter asc

    associator [=]

    Returns

    "${k₀}=${v₀},${k₁}=${v₁}..." | [kᵢ, vᵢ] ∈ x

function key

key: <K, V>(x: Map<K, V>, fr?: ReadFunction<number>) => K;
  • Pick an arbitrary key. [📘](https://github.com/nodef/extra-map/wiki/randomKey)

    Parameter x

    a map

    Parameter fr

    random number generator ([0, 1))

    Returns

    kᵢ | [kᵢ, vᵢ] ∈ x

function keys

keys: <K, V>(x: Map<K, V>) => IterableIterator<K>;
  • List all keys. [📘](https://github.com/nodef/extra-map/wiki/keys)

    Parameter x

    a map

    Returns

    k₀, k₁, ... | [kᵢ, vᵢ] ∈ x

function length

length: <K, V>(x: Map<K, V>) => number;
  • Find the size of a map. [📘](https://github.com/nodef/extra-map/wiki/size)

    Parameter x

    a map

    Returns

    |x|

function map

map: <K, V, W = V>(x: Map<K, V>, fm: MapFunction<K, V, V | W>) => Map<K, V | W>;
  • Transform values of a map. [📘](https://github.com/nodef/extra-map/wiki/map)

    Parameter x

    a map

    Parameter fm

    map function (v, k, x)

    Returns

    {[k₀, fm(v₀)], [k₁, fm(v₁)], ...} | [kᵢ, vᵢ] ∈ x

function map$

map$: <K, V>(x: Map<K, V>, fm: MapFunction<K, V, V>) => Map<K, V>;
  • Transform values of a map. [📘](https://github.com/nodef/extra-map/wiki/map$)

    Parameter x

    a map (updated)

    Parameter fm

    map function (v, k, x)

    Returns

    x = {[k₀, fm(v₀)], [k₁, fm(v₁)], ...} | [kᵢ, vᵢ] ∈ x

function max

max: <K, V, W = V>(
x: Map<K, V>,
fc?: CompareFunction<V | W> | null,
fm?: MapFunction<K, V, V | W> | null
) => V;
  • Find largest value. [📘](https://github.com/nodef/extra-map/wiki/max)

    Parameter x

    a map

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, k, x)

    Returns

    v | v ≥ vᵢ; [kᵢ, vᵢ] ∈ x

function maxEntry

maxEntry: <K, V, W = V>(
x: Map<K, V>,
fc?: CompareFunction<V | W> | null,
fm?: MapFunction<K, V, V | W> | null
) => [K, V];
  • Find largest entry. [📘](https://github.com/nodef/extra-map/wiki/maxEntry)

    Parameter x

    a map

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, k, x)

    Returns

    [max_key, max_value]

function min

min: <K, V, W = V>(
x: Map<K, V>,
fc?: CompareFunction<V | W> | null,
fm?: MapFunction<K, V, V | W> | null
) => V;
  • Find smallest value. [📘](https://github.com/nodef/extra-map/wiki/min)

    Parameter x

    a map

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, k, x)

    Returns

    v | v ≤ vᵢ; [kᵢ, vᵢ] ∈ x

function minEntry

minEntry: <K, V, W = V>(
x: Map<K, V>,
fc?: CompareFunction<V | W> | null,
fm?: MapFunction<K, V, V | W> | null
) => [K, V];
  • Find smallest entry. [📘](https://github.com/nodef/extra-map/wiki/minEntry)

    Parameter x

    a map

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, k, x)

    Returns

    [min_key, min_value]

function partition

partition: <K, V>(
x: Map<K, V>,
ft: TestFunction<K, V>
) => [Map<K, V>, Map<K, V>];
  • Segregate entries by test result. [📘](https://github.com/nodef/extra-map/wiki/partition)

    Parameter x

    a map

    Parameter ft

    test function (v, k, x)

    Returns

    [satisfies, doesnt]

function partitionAs

partitionAs: <K, V, W = V>(
x: Map<K, V>,
fm: MapFunction<K, V, V | W>
) => Map<V | W, Map<K, V>>;
  • Segregate entries by similarity. [📘](https://github.com/nodef/extra-map/wiki/partitionAs)

    Parameter x

    a map

    Parameter fm

    map function (v, k, x)

    Returns

    Map {key ⇒ values}

function randomEntry

randomEntry: <K, V>(x: Entries<K, V>, fr?: ReadFunction<number>) => [K, V];
  • Pick an arbitrary entry. [📘](https://github.com/nodef/extra-map/wiki/randomEntry)

    Parameter x

    a map

    Parameter fr

    random number generator ([0, 1))

    Returns

    [kᵢ, vᵢ] | [kᵢ, vᵢ] ∈ x

function randomKey

randomKey: <K, V>(x: Map<K, V>, fr?: ReadFunction<number>) => K;
  • Pick an arbitrary key. [📘](https://github.com/nodef/extra-map/wiki/randomKey)

    Parameter x

    a map

    Parameter fr

    random number generator ([0, 1))

    Returns

    kᵢ | [kᵢ, vᵢ] ∈ x

function randomSubset

randomSubset: <K, V>(
x: Map<K, V>,
n?: number,
fr?: ReadFunction<number> | null
) => Map<K, V>;
  • Pick an arbitrary subset. [📘](https://github.com/nodef/extra-map/wiki/randomSubset)

    Parameter x

    a map

    Parameter n

    number of entries [-1 ⇒ any]

    Parameter fr

    random number generator ([0, 1))

    Returns

    {[kᵢ, vᵢ], [kⱼ, vⱼ], ...} | [kᵢ, vᵢ], [kⱼ, vⱼ], ... ∈ x; |{[kᵢ, vᵢ], [kⱼ, vⱼ], ...}| = |x| if n<0 else n

function range

range: <K, V, W = V>(
x: Map<K, V>,
fc?: CompareFunction<V | W> | null,
fm?: MapFunction<K, V, V | W> | null
) => [V, V];
  • Find smallest and largest values. [📘](https://github.com/nodef/extra-map/wiki/range)

    Parameter x

    a map

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, k, x)

    Returns

    [min_value, max_value]

function rangeEntries

rangeEntries: <K, V, W = V>(
x: Map<K, V>,
fc?: CompareFunction<V | W> | null,
fm?: MapFunction<K, V, V | W> | null
) => [[K, V], [K, V]];
  • Find smallest and largest entries. [📘](https://github.com/nodef/extra-map/wiki/rangeEntries)

    Parameter x

    a map

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, k, x)

    Returns

    [min_entry, max_entry]

function reduce

reduce: <K, V, W = V>(
x: Map<K, V>,
fr: ReduceFunction<K, V, V | W>,
acc?: V | W
) => V | W;
  • Reduce values of set to a single value. [📘](https://github.com/nodef/extra-map/wiki/reduce)

    Parameter x

    a map

    Parameter fr

    reduce function (acc, v, k, x)

    Parameter acc

    initial value

    Returns

    fr(fr(acc, v₀), v₁)... | fr(acc, v₀) = v₀ if acc not given

function reject

reject: <K, V>(x: Map<K, V>, ft: TestFunction<K, V>) => Map<K, V>;
  • Discard entries which pass a test. [📘](https://github.com/nodef/extra-map/wiki/reject)

    Parameter x

    a map

    Parameter ft

    test function (v, k, x)

    Returns

    {[k₀, v₀], [k₁, v₁], ...} | ft(vᵢ) = false; [kᵢ, vᵢ] ∈ x

function reject$

reject$: <K, V>(x: Map<K, V>, ft: TestFunction<K, V>) => Map<K, V>;
  • Discard entries which pass a test. [📘](https://github.com/nodef/extra-map/wiki/reject$)

    Parameter x

    a map (updated)

    Parameter ft

    test function (v, k, x)

    Returns

    x = {[k₀, v₀], [k₁, v₁], ...} | ft(vᵢ) = false; [kᵢ, vᵢ] ∈ x

function rejectAt

rejectAt: <K, V>(x: Map<K, V>, ks: K[]) => Map<K, V>;
  • Discard values at given keys. [📘](https://github.com/nodef/extra-map/wiki/rejectAt)

    Parameter x

    a map

    Parameter ks

    keys

    Returns

    {[k₀, v₀], [k₁, v₁], ...} | kᵢ ∉ ks; [kᵢ, vᵢ] ∈ x

function rejectAt$

rejectAt$: <K, V>(x: Map<K, V>, ks: K[]) => Map<K, V>;
  • Discard values at given keys. [📘](https://github.com/nodef/extra-map/wiki/rejectAt$)

    Parameter x

    a map (updated)

    Parameter ks

    keys

    Returns

    x = {[k₀, v₀], [k₁, v₁], ...} | kᵢ ∉ ks; [kᵢ, vᵢ] ∈ x

function remove

remove: <K, V>(x: Entries<K, V>, k: K) => Map<K, V>;
  • Remove value at key. [📘](https://github.com/nodef/extra-map/wiki/remove)

    Parameter x

    a map

    Parameter k

    key

    Returns

    x \: [k]

function remove$

remove$: <K, V>(x: Map<K, V>, k: K) => Map<K, V>;
  • Remove value at key. [📘](https://github.com/nodef/extra-map/wiki/remove$)

    Parameter x

    a map (updated)

    Parameter k

    key

    Returns

    x = x \: [k]

function removePath$

removePath$: <K>(x: Map<K, any>, p: K[]) => Map<K, any>;
  • Remove value at path in a nested map. [📘](https://github.com/nodef/extra-map/wiki/removePath$)

    Parameter x

    a nested map (updated)

    Parameter p

    path

    Returns

    x = x \: [k₀][k₁][...] | [k₀, k₁, ...] = p

search: <K, V>(x: Map<K, V>, ft: TestFunction<K, V>) => K;
  • Find key of an entry passing a test. [📘](https://github.com/nodef/extra-map/wiki/search)

    Parameter x

    a map

    Parameter ft

    test function (v, k, x)

    Returns

    key of entry

function searchAll

searchAll: <K, V>(x: Map<K, V>, ft: TestFunction<K, V>) => K[];
  • Find keys of entries passing a test. [📘](https://github.com/nodef/extra-map/wiki/searchAll)

    Parameter x

    a map

    Parameter ft

    test function (v, k, x)

    Returns

    keys of entries

function searchValue

searchValue: <K, V, W = V>(
x: Map<K, V>,
v: V,
fc?: CompareFunction<V | W> | null,
fm?: MapFunction<K, V, V | W> | null
) => K;
  • Find a key with given value. [📘](https://github.com/nodef/extra-map/wiki/searchValue)

    Parameter x

    a map

    Parameter v

    search value

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, k, x)

    Returns

    key of value

function searchValueAll

searchValueAll: <K, V, W = V>(
x: Map<K, V>,
v: V,
fc?: CompareFunction<V | W> | null,
fm?: MapFunction<K, V, V | W> | null
) => K[];
  • Find keys with given value. [📘](https://github.com/nodef/extra-map/wiki/searchValueAll)

    Parameter x

    a map

    Parameter v

    search value

    Parameter fc

    compare function (a, b)

    Parameter fm

    map function (v, k, x)

    Returns

    keys of value

function set

set: <K, V>(x: Entries<K, V>, k: K, v: V) => Map<K, V>;
  • Set value at key. [📘](https://github.com/nodef/extra-map/wiki/set)

    Parameter x

    a map

    Parameter k

    key

    Parameter v

    value

    Returns

    x' | x' = x; x'[k] = v

function set$

set$: <K, V>(x: Map<K, V>, k: K, v: V) => Map<K, V>;
  • Set value at key. [📘](https://github.com/nodef/extra-map/wiki/set$)

    Parameter x

    a map (updated)

    Parameter k

    key

    Parameter v

    value

    Returns

    x | x[k] = v

function setPath$

setPath$: <K>(x: Map<K, any>, p: K[], v: any) => Map<K, any>;
  • Set value at path in a nested map. [📘](https://github.com/nodef/extra-map/wiki/setPath$)

    Parameter x

    a nested map (updated)

    Parameter p

    path

    Parameter v

    value

    Returns

    x | x[k₀][k₁][...] = v; [k₀, k₁, ...] = p

function size

size: <K, V>(x: Map<K, V>) => number;
  • Find the size of a map. [📘](https://github.com/nodef/extra-map/wiki/size)

    Parameter x

    a map

    Returns

    |x|

function some

some: <K, V>(x: Map<K, V>, ft: TestFunction<K, V>) => boolean;
  • Check if any value satisfies a test. [📘](https://github.com/nodef/extra-map/wiki/some)

    Parameter x

    a map

    Parameter ft

    test function (v, k, x)

    Returns

    true if ft(vᵢ) = true for some [kᵢ, vᵢ] ∈ x

function subset

subset: <K, V>(
x: Map<K, V>,
n?: number,
fr?: ReadFunction<number> | null
) => Map<K, V>;
  • Pick an arbitrary subset. [📘](https://github.com/nodef/extra-map/wiki/randomSubset)

    Parameter x

    a map

    Parameter n

    number of entries [-1 ⇒ any]

    Parameter fr

    random number generator ([0, 1))

    Returns

    {[kᵢ, vᵢ], [kⱼ, vⱼ], ...} | [kᵢ, vᵢ], [kⱼ, vⱼ], ... ∈ x; |{[kᵢ, vᵢ], [kⱼ, vⱼ], ...}| = |x| if n<0 else n

function subsets

subsets: <K, V>(x: Map<K, V>, n?: number) => IterableIterator<Map<K, V>>;
  • List all possible subsets. [📘](https://github.com/nodef/extra-map/wiki/subsets)

    Parameter x

    a map

    Parameter n

    number of entries [-1 ⇒ any]

    Returns

    entries selected by bit from 0..2^|x| if n<0; only of length n otherwise

function swap

swap: <K, V>(x: Entries<K, V>, k: K, l: K) => Map<K, V>;
  • Exchange two values. [📘](https://github.com/nodef/extra-map/wiki/swap)

    Parameter x

    a map

    Parameter k

    a key

    Parameter l

    another key

    Returns

    x' | x' = x; x'[k] = x[l]; x'[l] = x[k]

function swap$

swap$: <K, V>(x: Map<K, V>, k: K, l: K) => Map<K, V>;
  • Exchange two values. [📘](https://github.com/nodef/extra-map/wiki/swap$)

    Parameter x

    a map (updated)

    Parameter k

    a key

    Parameter l

    another key

    Returns

    x | x[i] ↔ x[j]

function symmetricDifference

symmetricDifference: <K, V>(x: Entries<K, V>, y: Entries<K, V>) => Map<K, V>;
  • Obtain entries not present in both maps. [📘](https://github.com/nodef/extra-map/wiki/symmetricDifference)

    Parameter x

    a map

    Parameter y

    another map

    Returns

    x-y ∪ y-x

function symmetricDifference$

symmetricDifference$: <K, V>(x: Map<K, V>, y: Entries<K, V>) => Map<K, V>;
  • Obtain entries not present in both maps. [📘](https://github.com/nodef/extra-map/wiki/symmetricDifference$)

    Parameter x

    a map (updated)

    Parameter y

    another map

    Returns

    x = x-y ∪ y-x

function tail

tail: <K, V>(x: Map<K, V>) => Map<K, V>;
  • Get a map without its first entry (default order). [📘](https://github.com/nodef/extra-map/wiki/tail)

    Parameter x

    a map

    Returns

    x \ {[k₀, v₀]} if x ≠ Φ else x | [k₀, v₀] ∈ x

function take

take: <K, V>(x: Map<K, V>, n?: number) => Map<K, V>;
  • Keep first n entries only (default order). [📘](https://github.com/nodef/extra-map/wiki/take)

    Parameter x

    a map

    Parameter n

    number of entries [1]

    Returns

    {[k₀, v₀], [k₁, v₁], ...} | [kᵢ, vᵢ] ∈ x and |{[k₀, v₀], [k₁, v₁], ...}| ≤ n

function take$

take$: <K, V>(x: Map<K, V>, n?: number) => Map<K, V>;
  • Keep first n entries only (default order). [📘](https://github.com/nodef/extra-map/wiki/take$)

    Parameter x

    a map (updated)

    Parameter n

    number of entries [1]

    Returns

    x = {[k₀, v₀], [k₁, v₁], ...} | [kᵢ, vᵢ] ∈ x and |{[k₀, v₀], [k₁, v₁], ...}| ≤ n

function union

union: <K, V>(
x: Entries<K, V>,
y: Entries<K, V>,
fc?: CombineFunction<V> | null
) => Map<K, V>;
  • Obtain entries present in any map. [📘](https://github.com/nodef/extra-map/wiki/union)

    Parameter x

    a map

    Parameter y

    another map

    Parameter fc

    combine function (a, b)

    Returns

    x ∪ y = {[kᵢ, vᵢ] | [kᵢ, vᵢ] ∈ x or [kᵢ, vᵢ] ∈ y}

function union$

union$: <K, V>(
x: Map<K, V>,
y: Entries<K, V>,
fc?: CombineFunction<V> | null
) => Map<K, V>;
  • Obtain entries present in any map. [📘](https://github.com/nodef/extra-map/wiki/union$)

    Parameter x

    a map (updated)

    Parameter y

    another map

    Parameter fc

    combine function (a, b)

    Returns

    x = x ∪ y = {[kᵢ, vᵢ] | [kᵢ, vᵢ] ∈ x or [kᵢ, vᵢ] ∈ y}

function unionKeys

unionKeys: <K, V>(...xs: Entries<K, V>[]) => Set<K>;
  • Obtain keys present in any map. [📘](https://github.com/nodef/extra-map/wiki/unionKeys)

    Parameter xs

    maps

    Returns

    [k₀, k₁, ...] | [kᵢ, vᵢ] ∈ x₀ ∪ x₁, ...; [x₀, x₁, ...] = xs

function values

values: <K, V>(x: Map<K, V>) => IterableIterator<V>;
  • List all values. [📘](https://github.com/nodef/extra-map/wiki/values)

    Parameter x

    a map

    Returns

    v₀, v₁, ... | [kᵢ, vᵢ] ∈ x

function zip

zip: <K, V, W = V>(
xs: Map<K, V>[],
fm?: MapFunction<K, V[], V[] | W> | null,
fe?: EndFunction,
vd?: V
) => Map<K, V[] | W>;
  • Combine matching entries from maps. [📘](https://github.com/nodef/extra-map/wiki/zip)

    Parameter xs

    maps

    Parameter fm

    map function (vs, k)

    Parameter fe

    end function (dones) [array.some]

    Parameter vd

    default value

    Returns

    [fm([x₀[k₀], x₁[k₀], ...]), fm([x₀[k₁], x₁[k₁], ...]), ...]

Type Aliases

type CombineFunction

type CombineFunction<V> = (a: V, b: V) => V;
  • Handle combining of two values. [📘](https://github.com/nodef/extra-map/wiki/CombineFunction)

    Parameter a

    a value

    Parameter b

    another value

    Returns

    combined value

type CompareFunction

type CompareFunction<V> = (a: V, b: V) => number;
  • Handle comparison of two values. [📘](https://github.com/nodef/extra-map/wiki/CompareFunction)

    Parameter a

    a value

    Parameter b

    another value

    Returns

    a<b: -ve, a=b: 0, a>b: +ve

type EndFunction

type EndFunction = (dones: boolean[]) => boolean;
  • Handle ending of a combined map. [📘](https://github.com/nodef/extra-map/wiki/EndFunction)

    Parameter dones

    iᵗʰ map done?

    Returns

    combined map done?

type Entries

type Entries<K, V> = Iterable<[K, V]>;
  • Entries is a list of key-value pairs, with unique keys. [📘](https://github.com/nodef/extra-map/wiki/Entries)

type Lists

type Lists<K, V> = [Iterable<K>, Iterable<V>];
  • Lists is a pair of key list and value list, with unique keys. [📘](https://github.com/nodef/extra-map/wiki/Lists)

type MapFunction

type MapFunction<K, V, W> = (v: V, k: K, x: Map<K, V>) => W;
  • Handle transformation of a value to another. [📘](https://github.com/nodef/extra-map/wiki/MapFunction)

    Parameter v

    value in map

    Parameter k

    key of value in map

    Parameter x

    map containing the value

    Returns

    transformed value

type ProcessFunction

type ProcessFunction<K, V> = (v: V, k: K, x: Map<K, V>) => void;
  • Handle processing of values in a map. [📘](https://github.com/nodef/extra-map/wiki/ProcessFunction)

    Parameter v

    value in map

    Parameter k

    key of value in map

    Parameter x

    map containing the value

type ReadFunction

type ReadFunction<V> = () => V;
  • Handle reading of a single value. [📘](https://github.com/nodef/extra-map/wiki/ReadFunction)

    Returns

    value

type ReduceFunction

type ReduceFunction<K, V, W> = (acc: W, v: V, k: K, x: Map<K, V>) => W;
  • Handle reduction of multiple values into a single value. [📘](https://github.com/nodef/extra-map/wiki/ReduceFunction)

    Parameter acc

    accumulator (temporary result)

    Parameter v

    value in map

    Parameter k

    key of value in map

    Parameter x

    map containing the value

    Returns

    reduced value

type TestFunction

type TestFunction<K, V> = (v: V, k: K, x: Map<K, V>) => boolean;
  • Handle selection of values in a map. [📘](https://github.com/nodef/extra-map/wiki/TestFunction)

    Parameter v

    value in map

    Parameter k

    key of value in map

    Parameter x

    map containing the value

    Returns

    selected?

Package Files (1)

Dependencies (0)

No dependencies.

Dev Dependencies (11)

Peer Dependencies (0)

No peer dependencies.

Badge

To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/extra-map.

  • Markdown
    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/extra-map)
  • HTML
    <a href="https://www.jsdocs.io/package/extra-map"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>