UNPKG

extra-map

Version:

A group of functions for working with Maps.

815 lines (805 loc) • 30.8 kB
import { MapFunction as MapFunction$1 } from 'extra-iterable'; /** * Entries is a list of key-value pairs, with unique keys. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/Entries) */ type Entries<K, V> = Iterable<[K, V]>; /** * Lists is a pair of key list and value list, with unique keys. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/Lists) */ type Lists<K, V> = [Iterable<K>, Iterable<V>]; /** * Handle reading of a single value. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/ReadFunction) * @returns value */ type ReadFunction<V> = () => V; /** * Handle combining of two values. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/CombineFunction) * @param a a value * @param b another value * @returns combined value */ type CombineFunction<V> = (a: V, b: V) => V; /** * Handle comparison of two values. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/CompareFunction) * @param a a value * @param b another value * @returns a<b: -ve, a=b: 0, a>b: +ve */ type CompareFunction<V> = (a: V, b: V) => number; /** * Handle processing of values in a map. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/ProcessFunction) * @param v value in map * @param k key of value in map * @param x map containing the value */ type ProcessFunction<K, V> = (v: V, k: K, x: Map<K, V>) => void; /** * Handle selection of values in a map. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/TestFunction) * @param v value in map * @param k key of value in map * @param x map containing the value * @returns selected? */ type TestFunction<K, V> = (v: V, k: K, x: Map<K, V>) => boolean; /** * Handle transformation of a value to another. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/MapFunction) * @param v value in map * @param k key of value in map * @param x map containing the value * @returns transformed value */ type MapFunction<K, V, 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) * @param acc accumulator (temporary result) * @param v value in map * @param k key of value in map * @param x map containing the value * @returns reduced value */ type ReduceFunction<K, V, W> = (acc: W, v: V, k: K, x: Map<K, V>) => W; /** * Handle ending of a combined map. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/EndFunction) * @param dones iᵗʰ map done? * @returns combined map done? */ type EndFunction = (dones: boolean[]) => boolean; /** * Check if value is a map. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/is) * @param v value * @returns v is a map? */ declare function is(v: any): v is Map<any, any>; /** * List all keys. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/keys) * @param x a map * @returns kā‚€, k₁, ... | [kįµ¢, vįµ¢] ∈ x */ declare function keys<K, V>(x: Map<K, V>): IterableIterator<K>; /** * List all values. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/values) * @param x a map * @returns vā‚€, v₁, ... | [kįµ¢, vįµ¢] ∈ x */ declare function values<K, V>(x: Map<K, V>): IterableIterator<V>; /** * List all key-value pairs. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/entries) * @param x a map * @returns [kā‚€, vā‚€], [k₁, v₁], ... | [kįµ¢, vįµ¢] ∈ x */ declare function entries<K, V>(x: Map<K, V>): IterableIterator<[K, V]>; /** * Convert entries to map. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/from) * @param x entries * @returns x as map */ declare function from<K, V>(x: Entries<K, V>): Map<K, V>; /** * Convert entries to map. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/from$) * @param x entries (updateable is map!) * @returns x as map */ declare function from$<K, V>(x: Entries<K, V>): Map<K, V>; /** * Convert lists to map. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/fromLists) * @param x lists, i.e. [keys, values] * @returns x as map */ declare function fromLists<K, V>(x: Lists<K, V>): Map<K, V>; /** * Create a map from keys. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/fromKeys) * @param x keys * @param fm map function for values (v, i, x) * @returns x as map */ declare function fromKeys<K, V = K>(x: Iterable<K>, fm?: MapFunction$1<K, K | V> | null): Map<K, K | V>; /** * Create a map from values. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/fromValues) * @param x values * @param fm map function for keys (v, i, x) * @returns x as map */ declare function fromValues<V, K = V>(x: Iterable<V>, fm?: MapFunction$1<V, V | K> | null): Map<V | K, V>; /** * Compare two maps. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/compare) * @param x a map * @param y another map * @param fc compare function (a, b) * @param fm map function (v, k, x) * @returns x=y: 0, otherwise: -ve/+ve */ declare function 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; /** * Check if two maps are equal. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/isEqual) * @param x a map * @param y another map * @param fc compare function (a, b) * @param fm map function (v, k, x) * @returns x = y? */ declare function 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; /** * Find the size of a map. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/size) * @param x a map * @returns |x| */ declare function size<K, V>(x: Map<K, V>): number; /** * Check if a map is empty. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/isEmpty) * @param x a map * @returns |x| = 0? */ declare function isEmpty<K, V>(x: Map<K, V>): boolean; /** * Get value at key. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/get) * @param x a map * @param k key * @returns x[k] */ declare function get<K, V>(x: Map<K, V>, k: K): V; /** * Get values at keys. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/getAll) * @param x a map * @param ks keys * @returns [x[kā‚€], x[k₁], ...] | [kā‚€, k₁, ...] = ks */ declare function getAll<K, V>(x: Map<K, V>, ks: K[]): V[]; /** * Get value at path in a nested map. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/getPath) * @param x a nested map * @param p path * @returns x[kā‚€][k₁][...] | [kā‚€, k₁, ...] = p */ declare function getPath<K>(x: Map<K, any>, p: K[]): any; /** * Check if nested map has a path. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/hasPath) * @param x a nested map * @param p path * @returns x[kā‚€][k₁][...] exists? | [kā‚€, k₁, ...] = p */ declare function hasPath<K>(x: Map<K, any>, p: K[]): boolean; /** * Set value at key. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/set) * @param x a map * @param k key * @param v value * @returns x' | x' = x; x'[k] = v */ declare function 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$) * @param x a map (updated) * @param k key * @param v value * @returns x | x[k] = v */ declare function set$<K, V>(x: Map<K, V>, k: K, v: V): Map<K, V>; /** * Set value at path in a nested map. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/setPath$) * @param x a nested map (updated) * @param p path * @param v value * @returns x | x[kā‚€][k₁][...] = v; [kā‚€, k₁, ...] = p */ declare function setPath$<K>(x: Map<K, any>, p: K[], v: any): Map<K, any>; /** * Exchange two values. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/swap) * @param x a map * @param k a key * @param l another key * @returns x' | x' = x; x'[k] = x[l]; x'[l] = x[k] */ declare function 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$) * @param x a map (updated) * @param k a key * @param l another key * @returns x | x[i] ↔ x[j] */ declare function swap$<K, V>(x: Map<K, V>, k: K, l: K): Map<K, V>; /** * Remove value at key. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/remove) * @param x a map * @param k key * @returns x \\: [k] */ declare function remove<K, V>(x: Entries<K, V>, k: K): Map<K, V>; /** * Remove value at key. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/remove$) * @param x a map (updated) * @param k key * @returns x = x \\: [k] */ declare function remove$<K, V>(x: Map<K, V>, k: K): Map<K, V>; /** * Remove value at path in a nested map. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/removePath$) * @param x a nested map (updated) * @param p path * @returns x = x \\: [kā‚€][k₁][...] | [kā‚€, k₁, ...] = p */ declare function removePath$<K>(x: Map<K, any>, p: K[]): Map<K, any>; /** * Count values which satisfy a test. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/count) * @param x a map * @param ft test function (v, k, x) * @returns Ī£tįµ¢ | tįµ¢ = 1 if ft(vįµ¢) else 0; [kįµ¢, vįµ¢] ∈ x */ declare function count<K, V>(x: Map<K, V>, ft: TestFunction<K, V>): number; /** * Count occurrences of values. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/countAs) * @param x a map * @param fm map function (v, k, x) * @returns Map \{value ⇒ count\} */ declare function countAs<K, V, W = V>(x: Map<K, V>, fm?: MapFunction<K, V, V | W> | null): Map<V | W, number>; /** * Find smallest value. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/min) * @param x a map * @param fc compare function (a, b) * @param fm map function (v, k, x) * @returns v | v ≤ vįµ¢; [kįµ¢, vįµ¢] ∈ x */ declare function min<K, V, W = V>(x: Map<K, V>, fc?: CompareFunction<V | W> | null, fm?: MapFunction<K, V, V | W> | null): V; /** * Find smallest entry. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/minEntry) * @param x a map * @param fc compare function (a, b) * @param fm map function (v, k, x) * @returns [min_key, min_value] */ declare function minEntry<K, V, W = V>(x: Map<K, V>, fc?: CompareFunction<V | W> | null, fm?: MapFunction<K, V, V | W> | null): [K, V]; /** * Find largest value. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/max) * @param x a map * @param fc compare function (a, b) * @param fm map function (v, k, x) * @returns v | v ≄ vįµ¢; [kįµ¢, vįµ¢] ∈ x */ declare function max<K, V, W = V>(x: Map<K, V>, fc?: CompareFunction<V | W> | null, fm?: MapFunction<K, V, V | W> | null): V; /** * Find largest entry. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/maxEntry) * @param x a map * @param fc compare function (a, b) * @param fm map function (v, k, x) * @returns [max_key, max_value] */ declare function maxEntry<K, V, W = V>(x: Map<K, V>, fc?: CompareFunction<V | W> | null, fm?: MapFunction<K, V, V | W> | null): [K, V]; /** * Find smallest and largest values. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/range) * @param x a map * @param fc compare function (a, b) * @param fm map function (v, k, x) * @returns [min_value, max_value] */ declare function 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 entries. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/rangeEntries) * @param x a map * @param fc compare function (a, b) * @param fm map function (v, k, x) * @returns [min_entry, max_entry] */ declare function 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]]; /** * Get first entry from map (default order). * [šŸ“˜](https://github.com/nodef/extra-map/wiki/head) * @param x a map * @param ed default entry * @returns [kā‚€, vā‚€] if x ≠ Φ else ed | [kā‚€, vā‚€] ∈ x */ declare function head<K, V>(x: Entries<K, V>, ed?: [K, V]): [K, V]; /** * Get a map without its first entry (default order). * [šŸ“˜](https://github.com/nodef/extra-map/wiki/tail) * @param x a map * @returns x \\ \{[kā‚€, vā‚€]\} if x ≠ Φ else x | [kā‚€, vā‚€] ∈ x */ declare function tail<K, V>(x: Map<K, V>): Map<K, V>; /** * Keep first n entries only (default order). * [šŸ“˜](https://github.com/nodef/extra-map/wiki/take) * @param x a map * @param n number of entries [1] * @returns \{[kā‚€, vā‚€], [k₁, v₁], ...\} | [kįµ¢, vįµ¢] ∈ x and |\{[kā‚€, vā‚€], [k₁, v₁], ...\}| ≤ n */ declare function 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$) * @param x a map (updated) * @param n number of entries [1] * @returns x = \{[kā‚€, vā‚€], [k₁, v₁], ...\} | [kįµ¢, vįµ¢] ∈ x and |\{[kā‚€, vā‚€], [k₁, v₁], ...\}| ≤ n */ declare function take$<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) * @param x a map * @param n number of entries [1] * @returns \{[kā‚™, vā‚™], [kā‚™ā‚Šā‚, vā‚™ā‚Šā‚], ...\} | [kįµ¢, vįµ¢] ∈ x and |\{[kā‚™, vā‚™], [kā‚™ā‚Šā‚, vā‚™ā‚Šā‚], ...\}| ≤ max(|x| - n, 0) */ declare function 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$) * @param x a map (updated) * @param n number of entries [1] * @returns x = \{[kā‚™, vā‚™], [kā‚™ā‚Šā‚, vā‚™ā‚Šā‚], ...\} | [kįµ¢, vįµ¢] ∈ x and |\{[kā‚™, vā‚™], [kā‚™ā‚Šā‚, vā‚™ā‚Šā‚], ...\}| ≤ max(|x| - n, 0) */ declare function drop$<K, V>(x: Map<K, V>, n?: number): Map<K, V>; /** * List all possible subsets. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/subsets) * @param x a map * @param n number of entries [-1 ⇒ any] * @returns entries selected by bit from 0..2^|x| if n<0; only of length n otherwise */ declare function subsets<K, V>(x: Map<K, V>, n?: number): IterableIterator<Map<K, V>>; /** * Pick an arbitrary key. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/randomKey) * @param x a map * @param fr random number generator ([0, 1)) * @returns kįµ¢ | [kįµ¢, vįµ¢] ∈ x */ declare function randomKey<K, V>(x: Map<K, V>, fr?: ReadFunction<number>): K; /** * Pick an arbitrary entry. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/randomEntry) * @param x a map * @param fr random number generator ([0, 1)) * @returns [kįµ¢, vįµ¢] | [kįµ¢, vįµ¢] ∈ x */ declare function randomEntry<K, V>(x: Entries<K, V>, fr?: ReadFunction<number>): [K, V]; /** * Pick an arbitrary subset. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/randomSubset) * @param x a map * @param n number of entries [-1 ⇒ any] * @param 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 */ declare function randomSubset<K, V>(x: Map<K, V>, n?: number, fr?: ReadFunction<number> | null): Map<K, V>; /** * Check if map has a key. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/has) * @param x a map * @param k search key * @returns [k, *] ∈ x? */ declare function has<K, V>(x: Map<K, V>, k: K): boolean; /** * Check if map has a value. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/hasValue) * @param x a map * @param v search value * @param fc compare function (a, b) * @param fm map function (v, k, x) * @returns [*, v] ∈ x? */ declare function 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 an entry. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/hasEntry) * @param x a map * @param e search entry ([k, v]) * @param fc compare function (a, b) * @param fm map function (v, k, x) * @returns [k, v] ∈ x? | [k, v] = e */ declare function 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 a subset. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/hasSubset) * @param x a map * @param y search subset * @param fc compare function (a, b) * @param fm map function (v, k, x) * @returns y āŠ† x? */ declare function 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; /** * Find first value passing a test (default order). * [šŸ“˜](https://github.com/nodef/extra-map/wiki/find) * @param x a map * @param ft test function (v, k, x) * @returns first v | ft(v) = true; [k, v] ∈ x */ declare function find<K, V>(x: Map<K, V>, ft: TestFunction<K, V>): V; /** * Find values passing a test. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/findAll) * @param x a map * @param ft test function (v, k, x) * @returns [vā‚€, v₁, ...] | ft(vįµ¢) = true; [kįµ¢, vįµ¢] ∈ x */ declare function findAll<K, V>(x: Map<K, V>, ft: TestFunction<K, V>): V[]; /** * Find key of an entry passing a test. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/search) * @param x a map * @param ft test function (v, k, x) * @returns key of entry */ declare function search<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) * @param x a map * @param ft test function (v, k, x) * @returns keys of entries */ declare function searchAll<K, V>(x: Map<K, V>, ft: TestFunction<K, V>): K[]; /** * Find a key with given value. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/searchValue) * @param x a map * @param v search value * @param fc compare function (a, b) * @param fm map function (v, k, x) * @returns key of value */ declare function 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 keys with given value. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/searchValueAll) * @param x a map * @param v search value * @param fc compare function (a, b) * @param fm map function (v, k, x) * @returns keys of value */ declare function searchValueAll<K, V, W = V>(x: Map<K, V>, v: V, fc?: CompareFunction<V | W> | null, fm?: MapFunction<K, V, V | W> | null): K[]; /** * Call a function for each value. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/forEach) * @param x a map * @param fp process function (v, k, x) */ declare function forEach<K, V>(x: Map<K, V>, fp: ProcessFunction<K, V>): void; /** * Check if any value satisfies a test. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/some) * @param x a map * @param ft test function (v, k, x) * @returns true if ft(vįµ¢) = true for some [kįµ¢, vįµ¢] ∈ x */ declare function some<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) * @param x a map * @param ft test function (v, k, x) * @returns true if ft(vįµ¢) = true for all [kįµ¢, vįµ¢] ∈ x */ declare function every<K, V>(x: Map<K, V>, ft: TestFunction<K, V>): boolean; /** * Transform values of a map. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/map) * @param x a map * @param fm map function (v, k, x) * @returns \{[kā‚€, fm(vā‚€)], [k₁, fm(v₁)], ...\} | [kįµ¢, vįµ¢] ∈ x */ declare function 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$) * @param x a map (updated) * @param fm map function (v, k, x) * @returns x = \{[kā‚€, fm(vā‚€)], [k₁, fm(v₁)], ...\} | [kįµ¢, vįµ¢] ∈ x */ declare function map$<K, V>(x: Map<K, V>, fm: MapFunction<K, V, V>): Map<K, V>; /** * Reduce values of set to a single value. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/reduce) * @param x a map * @param fr reduce function (acc, v, k, x) * @param acc initial value * @returns fr(fr(acc, vā‚€), v₁)... | fr(acc, vā‚€) = vā‚€ if acc not given */ declare function reduce<K, V, W = V>(x: Map<K, V>, fr: ReduceFunction<K, V, V | W>, acc?: V | W): V | W; /** * Keep entries which pass a test. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/filter) * @param x a map * @param ft test function (v, k, x) * @returns \{[kā‚€, vā‚€], [k₁, v₁], ...\} | ft(vįµ¢) = true; [kįµ¢, vįµ¢] ∈ x */ declare function 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$) * @param x an map (updated) * @param ft test function (v, k, x) * @returns x = \{[kā‚€, vā‚€], [k₁, v₁], ...\} | ft(vįµ¢) = true; [kįµ¢, vįµ¢] ∈ x */ declare function filter$<K, V>(x: Map<K, V>, ft: TestFunction<K, V>): Map<K, V>; /** * Keep values at given keys. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/filterAt) * @param x a map * @param ks keys * @returns \{[kā‚€, vā‚€], [k₁, v₁], ...\} | kįµ¢ ∈ ks; [kįµ¢, vįµ¢] ∈ x */ declare function 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$) * @param x a map (updated) * @param ks keys * @returns x = \{[kā‚€, vā‚€], [k₁, v₁], ...\} | kįµ¢ ∈ ks; [kįµ¢, vįµ¢] ∈ x */ declare function filterAt$<K, V>(x: Map<K, V>, ks: K[]): Map<K, V>; /** * Discard entries which pass a test. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/reject) * @param x a map * @param ft test function (v, k, x) * @returns \{[kā‚€, vā‚€], [k₁, v₁], ...\} | ft(vįµ¢) = false; [kįµ¢, vįµ¢] ∈ x */ declare function 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$) * @param x a map (updated) * @param ft test function (v, k, x) * @returns x = \{[kā‚€, vā‚€], [k₁, v₁], ...\} | ft(vįµ¢) = false; [kįµ¢, vįµ¢] ∈ x */ declare function reject$<K, V>(x: Map<K, V>, ft: TestFunction<K, V>): Map<K, V>; /** * Discard values at given keys. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/rejectAt) * @param x a map * @param ks keys * @returns \{[kā‚€, vā‚€], [k₁, v₁], ...\} | kįµ¢ āˆ‰ ks; [kįµ¢, vįµ¢] ∈ x */ declare function 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$) * @param x a map (updated) * @param ks keys * @returns x = \{[kā‚€, vā‚€], [k₁, v₁], ...\} | kįµ¢ āˆ‰ ks; [kįµ¢, vįµ¢] ∈ x */ declare function rejectAt$<K, V>(x: Map<K, V>, ks: K[]): Map<K, V>; /** * Flatten nested map to given depth. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/flat) * @param x a nested map * @param n maximum depth [-1 ⇒ all] * @param fm map function (v, k, x) * @param ft test function for flatten (v, k, x) [is] * @returns flat map */ declare function 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, based on map function. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/flatMap) * @param x a nested map * @param fm map function (v, k, x) * @param ft test function for flatten (v, k, x) [is] * @returns flat map */ declare function flatMap<K>(x: Map<K, any>, fm?: MapFunction<K, any, any> | null, ft?: TestFunction<K, any> | null): Map<K, any>; /** * Combine matching entries from maps. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/zip) * @param xs maps * @param fm map function (vs, k) * @param fe end function (dones) [array.some] * @param vd default value * @returns [fm([xā‚€[kā‚€], x₁[kā‚€], ...]), fm([xā‚€[k₁], x₁[k₁], ...]), ...] */ declare function zip<K, V, W = V>(xs: Map<K, V>[], fm?: MapFunction<K, V[], V[] | W> | null, fe?: EndFunction, vd?: V): Map<K, V[] | W>; /** * Segregate entries by test result. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/partition) * @param x a map * @param ft test function (v, k, x) * @returns [satisfies, doesnt] */ declare function partition<K, V>(x: Map<K, V>, ft: TestFunction<K, V>): [Map<K, V>, Map<K, V>]; /** * Segregate entries by similarity. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/partitionAs) * @param x a map * @param fm map function (v, k, x) * @returns Map \{key ⇒ values\} */ declare function partitionAs<K, V, W = V>(x: Map<K, V>, fm: MapFunction<K, V, V | W>): Map<V | W, Map<K, V>>; /** * Break map into chunks of given size. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/chunk) * @param x a map * @param n chunk size [1] * @param s chunk step [n] * @returns [x[0..n], x[s..s+n], x[2s..2s+n], ...] */ declare function chunk<K, V>(x: Map<K, V>, n?: number, s?: number): Map<K, V>[]; /** * Append entries from maps, preferring last. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/concat) * @param xs maps * @returns xā‚€ ∪ x₁ ∪ ... | [xā‚€, x₁, ...] = xs */ declare function concat<K, V>(...xs: Entries<K, V>[]): Map<K, V>; /** * Append entries from maps, preferring last. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/concat$) * @param x a map (updated) * @param ys other maps * @returns x = x ∪ yā‚€ ∪ y₁ ∪ ... | [yā‚€, y₁, ...] = ys */ declare function concat$<K, V>(x: Map<K, V>, ...ys: Entries<K, V>[]): Map<K, V>; /** * Join entries together into a string. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/join) * @param x a map * @param sep separator [,] * @param asc associator [=] * @returns "$\{kā‚€\}=$\{vā‚€\},$\{k₁\}=$\{v₁\}..." | [kįµ¢, vįµ¢] ∈ x */ declare function join<K, V>(x: Entries<K, V>, sep?: string, asc?: string): string; /** * Check if maps have no common keys. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/isDisjoint) * @param x a map * @param y another map * @returns x ∩ y = Φ? */ declare function isDisjoint<K, V>(x: Map<K, V>, y: Entries<K, V>): boolean; /** * Obtain keys present in any map. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/unionKeys) * @param xs maps * @returns [kā‚€, k₁, ...] | [kįµ¢, vįµ¢] ∈ xā‚€ ∪ x₁, ...; [xā‚€, x₁, ...] = xs */ declare function unionKeys<K, V>(...xs: Entries<K, V>[]): Set<K>; /** * Obtain entries present in any map. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/union) * @param x a map * @param y another map * @param fc combine function (a, b) * @returns x ∪ y = \{[kįµ¢, vįµ¢] | [kįµ¢, vįµ¢] ∈ x or [kįµ¢, vįµ¢] ∈ y\} */ declare function 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$) * @param x a map (updated) * @param y another map * @param fc combine function (a, b) * @returns x = x ∪ y = \{[kįµ¢, vįµ¢] | [kįµ¢, vįµ¢] ∈ x or [kįµ¢, vįµ¢] ∈ y\} */ declare function union$<K, V>(x: Map<K, V>, y: Entries<K, V>, fc?: CombineFunction<V> | null): Map<K, V>; /** * Obtain keys present in all maps. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/intersectionKeys) * @param xs maps * @returns [kā‚€, k₁, ...] | [kįµ¢, vįµ¢] ∈ xā‚€ ∩ x₁, ...; [xā‚€, x₁, ...] = xs */ declare function intersectionKeys<K, V>(...xs: Map<K, V>[]): Set<K>; /** * Obtain entries present in both maps. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/intersection) * @param x a map * @param y another map * @param fc combine function (a, b) * @returns x ∩ y = \{[kįµ¢, vįµ¢] | [kįµ¢, vįµ¢] ∈ x and [kįµ¢, vįµ¢] ∈ y\} */ declare function 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$) * @param x a map (updated) * @param y another map * @param fc combine function (a, b) * @returns x = x ∩ y = \{[kįµ¢, vįµ¢] | [kįµ¢, vįµ¢] ∈ x and [kįµ¢, vįµ¢] ∈ y\} */ declare function intersection$<K, V>(x: Map<K, V>, y: Map<K, V>, fc?: CombineFunction<V> | null): Map<K, V>; /** * Obtain entries not present in another map. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/difference) * @param x a map * @param y another map * @returns x - y = \{[kįµ¢, vįµ¢] | [kįµ¢, vįµ¢] ∈ x, [kįµ¢, *] āˆ‰ y\} */ declare function 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$) * @param x a map (updated) * @param y another map * @returns x = x - y = \{[kįµ¢, vįµ¢] | [kįµ¢, vįµ¢] ∈ x, [kįµ¢, *] āˆ‰ y\} */ declare function difference$<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) * @param x a map * @param y another map * @returns x-y ∪ y-x */ declare function 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$) * @param x a map (updated) * @param y another map * @returns x = x-y ∪ y-x */ declare function symmetricDifference$<K, V>(x: Map<K, V>, y: Entries<K, V>): Map<K, V>; /** * List cartesian product of maps. * [šŸ“˜](https://github.com/nodef/extra-map/wiki/cartesianProduct) * @param xs maps * @param fm map function (vs, i) * @returns xā‚€ Ɨ x₁ Ɨ ... = \{\{[kā‚€, vā‚€], [k₁, v₁], ...\} | [kā‚€, vā‚€] ∈ xā‚€, [k₁, v₁] ∈ x₁, ...]\} */ declare function 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>; export { type CombineFunction, type CompareFunction, type EndFunction, type Entries, type Lists, type MapFunction, type ProcessFunction, type ReadFunction, type ReduceFunction, type TestFunction, cartesianProduct, chunk, compare, concat, concat$, count, countAs, difference, difference$, drop, drop$, entries, randomEntry as entry, every, filter, filter$, filterAt, filterAt$, find, findAll, flat, flatMap, forEach, from, from$, from as fromEntries, from$ as fromEntries$, fromKeys, fromLists, fromValues, get, getAll, getPath, has, hasEntry, has as hasKey, hasPath, hasSubset, hasValue, head, intersection, intersection$, intersectionKeys, is, isDisjoint, isEmpty, isEqual, join, randomKey as key, keys, size as length, map, map$, max, maxEntry, min, minEntry, partition, partitionAs, randomEntry, randomKey, randomSubset, range, rangeEntries, reduce, reject, reject$, rejectAt, rejectAt$, remove, remove$, removePath$, search, searchAll, searchValue, searchValueAll, set, set$, setPath$, size, some, randomSubset as subset, subsets, swap, swap$, symmetricDifference, symmetricDifference$, tail, take, take$, union, union$, unionKeys, values, zip };