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