You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

@rimbu/collection-types

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.7.5 to 0.8.0

221

dist/main/map/base.js

@@ -56,52 +56,45 @@ "use strict";

};
}
Object.defineProperty(ContextBase.prototype, "_types", {
get: function () {
return undefined;
},
enumerable: false,
configurable: true
});
ContextBase.prototype.mergeAllWith = function (fillValue, mergeFun) {
var sources = [];
for (var _i = 2; _i < arguments.length; _i++) {
sources[_i - 2] = arguments[_i];
}
var builder = this.builder();
var i = -1;
var length = sources.length;
while (++i < sources.length) {
var entry = void 0;
var iter = stream_1.Stream.from(sources[i])[Symbol.iterator]();
var _loop_1 = function () {
var key = entry[0];
var value = entry[1];
var index = i;
builder.modifyAt(key, {
ifNew: function () {
var row = Array(length).fill(fillValue);
row[index] = value;
return row;
},
ifExists: function (row) {
row[index] = value;
return row;
},
this.mergeAllWith = function () {
var sources = [];
for (var _i = 0; _i < arguments.length; _i++) {
sources[_i] = arguments[_i];
}
return function (fillValue, mergeFun) {
var builder = _this.builder();
var i = -1;
var length = sources.length;
while (++i < sources.length) {
var entry = void 0;
var iter = stream_1.Stream.from(sources[i])[Symbol.iterator]();
var _loop_1 = function () {
var key = entry[0];
var value = entry[1];
var index = i;
builder.modifyAt(key, {
ifNew: function () {
var row = Array(length).fill(fillValue);
row[index] = value;
return row;
},
ifExists: function (row) {
row[index] = value;
return row;
},
});
};
while (undefined !== (entry = iter.fastNext())) {
_loop_1();
}
}
return builder.buildMapValues(function (row, key) {
return mergeFun.apply(void 0, (0, tslib_1.__spreadArray)([key], (0, tslib_1.__read)(row), false));
});
};
while (undefined !== (entry = iter.fastNext())) {
_loop_1();
};
this.mergeAll = function (fillValue) {
var sources = [];
for (var _i = 1; _i < arguments.length; _i++) {
sources[_i - 1] = arguments[_i];
}
}
return builder.buildMapValues(function (row, key) {
return mergeFun.apply(void 0, (0, tslib_1.__spreadArray)([key], (0, tslib_1.__read)(row), false));
});
};
ContextBase.prototype.mergeAll = function (fillValue) {
var sources = [];
for (var _i = 1; _i < arguments.length; _i++) {
sources[_i - 1] = arguments[_i];
}
return this.mergeAllWith.apply(this, (0, tslib_1.__spreadArray)([fillValue,
function (key) {
return _this.mergeAllWith.apply(_this, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(sources), false))(fillValue, function (key) {
var values = [];

@@ -112,65 +105,67 @@ for (var _i = 1; _i < arguments.length; _i++) {

return values;
}], (0, tslib_1.__read)(sources), false));
};
ContextBase.prototype.mergeWith = function (mergeFun) {
var sources = [];
for (var _i = 1; _i < arguments.length; _i++) {
sources[_i - 1] = arguments[_i];
}
if (stream_1.Stream.from(sources).some(stream_1.StreamSource.isEmptyInstance)) {
return this.empty();
}
var builder = this.builder();
var i = -1;
var length = sources.length;
while (++i < sources.length) {
var entry_1 = void 0;
var iter_1 = stream_1.Stream.from(sources[i])[Symbol.iterator]();
var _loop_2 = function () {
var key = entry_1[0];
var value = entry_1[1];
var index = i;
builder.modifyAt(key, {
ifNew: function (nothing) {
if (index > 0)
return nothing;
var row = [value];
return row;
},
ifExists: function (row, remove) {
if (row.length !== index)
return remove;
row.push(value);
return row;
},
});
};
this.mergeWith = function () {
var sources = [];
for (var _i = 0; _i < arguments.length; _i++) {
sources[_i] = arguments[_i];
}
return function (mergeFun) {
if (stream_1.Stream.from(sources).some(stream_1.StreamSource.isEmptyInstance)) {
return _this.empty();
}
var builder = _this.builder();
var i = -1;
var length = sources.length;
while (++i < sources.length) {
var entry_1 = void 0;
var iter_1 = stream_1.Stream.from(sources[i])[Symbol.iterator]();
var _loop_2 = function () {
var key = entry_1[0];
var value = entry_1[1];
var index = i;
builder.modifyAt(key, {
ifNew: function (nothing) {
if (index > 0)
return nothing;
var row = [value];
return row;
},
ifExists: function (row, remove) {
if (row.length !== index)
return remove;
row.push(value);
return row;
},
});
};
while (undefined !== (entry_1 = iter_1.fastNext())) {
_loop_2();
}
}
// remove all rows that are not full
var firstSource = sources[0];
var entry;
var iter = stream_1.Stream.from(firstSource)[Symbol.iterator]();
while (undefined !== (entry = iter.fastNext())) {
var key = entry[0];
builder.modifyAt(key, {
ifExists: function (row, remove) {
if (row.length !== length)
return remove;
return row;
},
});
}
return builder.buildMapValues(function (row, key) {
return mergeFun.apply(void 0, (0, tslib_1.__spreadArray)([key], (0, tslib_1.__read)(row), false));
});
};
while (undefined !== (entry_1 = iter_1.fastNext())) {
_loop_2();
};
this.merge = function () {
var sources = [];
for (var _i = 0; _i < arguments.length; _i++) {
sources[_i] = arguments[_i];
}
}
// remove all rows that are not full
var firstSource = sources[0];
var entry;
var iter = stream_1.Stream.from(firstSource)[Symbol.iterator]();
while (undefined !== (entry = iter.fastNext())) {
var key = entry[0];
builder.modifyAt(key, {
ifExists: function (row, remove) {
if (row.length !== length)
return remove;
return row;
},
});
}
return builder.buildMapValues(function (row, key) {
return mergeFun.apply(void 0, (0, tslib_1.__spreadArray)([key], (0, tslib_1.__read)(row), false));
});
};
ContextBase.prototype.merge = function () {
var sources = [];
for (var _i = 0; _i < arguments.length; _i++) {
sources[_i] = arguments[_i];
}
return this.mergeWith.apply(this, (0, tslib_1.__spreadArray)([function (key) {
return _this.mergeWith.apply(_this, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(sources), false))(function (key) {
var values = [];

@@ -181,4 +176,12 @@ for (var _i = 1; _i < arguments.length; _i++) {

return values;
}], (0, tslib_1.__read)(sources), false));
};
});
};
}
Object.defineProperty(ContextBase.prototype, "_types", {
get: function () {
return undefined;
},
enumerable: false,
configurable: true
});
return ContextBase;

@@ -185,0 +188,0 @@ }());

@@ -41,2 +41,84 @@ import { Reducer } from '@rimbu/common';

};
this.mergeAllWith = (...sources) => {
return (fillValue, mergeFun) => {
const builder = this.builder();
let i = -1;
const length = sources.length;
while (++i < sources.length) {
let entry;
const iter = Stream.from(sources[i])[Symbol.iterator]();
while (undefined !== (entry = iter.fastNext())) {
const key = entry[0];
const value = entry[1];
const index = i;
builder.modifyAt(key, {
ifNew() {
const row = Array(length).fill(fillValue);
row[index] = value;
return row;
},
ifExists(row) {
row[index] = value;
return row;
},
});
}
}
return builder.buildMapValues((row, key) => mergeFun(key, ...row));
};
};
this.mergeAll = (fillValue, ...sources) => {
return this.mergeAllWith(...sources)(fillValue, (key, ...values) => values);
};
this.mergeWith = (...sources) => {
return (mergeFun) => {
if (Stream.from(sources).some(StreamSource.isEmptyInstance)) {
return this.empty();
}
const builder = this.builder();
let i = -1;
const length = sources.length;
while (++i < sources.length) {
let entry;
const iter = Stream.from(sources[i])[Symbol.iterator]();
while (undefined !== (entry = iter.fastNext())) {
const key = entry[0];
const value = entry[1];
const index = i;
builder.modifyAt(key, {
ifNew(nothing) {
if (index > 0)
return nothing;
const row = [value];
return row;
},
ifExists(row, remove) {
if (row.length !== index)
return remove;
row.push(value);
return row;
},
});
}
}
// remove all rows that are not full
const firstSource = sources[0];
let entry;
const iter = Stream.from(firstSource)[Symbol.iterator]();
while (undefined !== (entry = iter.fastNext())) {
const key = entry[0];
builder.modifyAt(key, {
ifExists(row, remove) {
if (row.length !== length)
return remove;
return row;
},
});
}
return builder.buildMapValues((row, key) => mergeFun(key, ...row));
};
};
this.merge = (...sources) => {
return this.mergeWith(...sources)((key, ...values) => values);
};
}

@@ -46,80 +128,2 @@ get _types() {

}
mergeAllWith(fillValue, mergeFun, ...sources) {
const builder = this.builder();
let i = -1;
const length = sources.length;
while (++i < sources.length) {
let entry;
const iter = Stream.from(sources[i])[Symbol.iterator]();
while (undefined !== (entry = iter.fastNext())) {
const key = entry[0];
const value = entry[1];
const index = i;
builder.modifyAt(key, {
ifNew() {
const row = Array(length).fill(fillValue);
row[index] = value;
return row;
},
ifExists(row) {
row[index] = value;
return row;
},
});
}
}
return builder.buildMapValues((row, key) => mergeFun(key, ...row));
}
mergeAll(fillValue, ...sources) {
return this.mergeAllWith(fillValue, (key, ...values) => values, ...sources);
}
mergeWith(mergeFun, ...sources) {
if (Stream.from(sources).some(StreamSource.isEmptyInstance)) {
return this.empty();
}
const builder = this.builder();
let i = -1;
const length = sources.length;
while (++i < sources.length) {
let entry;
const iter = Stream.from(sources[i])[Symbol.iterator]();
while (undefined !== (entry = iter.fastNext())) {
const key = entry[0];
const value = entry[1];
const index = i;
builder.modifyAt(key, {
ifNew(nothing) {
if (index > 0)
return nothing;
const row = [value];
return row;
},
ifExists(row, remove) {
if (row.length !== index)
return remove;
row.push(value);
return row;
},
});
}
}
// remove all rows that are not full
const firstSource = sources[0];
let entry;
const iter = Stream.from(firstSource)[Symbol.iterator]();
while (undefined !== (entry = iter.fastNext())) {
const key = entry[0];
builder.modifyAt(key, {
ifExists(row, remove) {
if (row.length !== length)
return remove;
return row;
},
});
}
return builder.buildMapValues((row, key) => mergeFun(key, ...row));
}
merge(...sources) {
return this.mergeWith((key, ...values) => values, ...sources);
}
}

@@ -126,0 +130,0 @@ RMapBase.ContextBase = ContextBase;

import type { Token } from '@rimbu/base';
import type { ArrayNonEmpty, OptLazy, OptLazyOr, RelatedTo, SuperOf, ToJSON, TraverseState, Update } from '@rimbu/common';
import type { ArrayNonEmpty, OptLazy, OptLazyOr, RelatedTo, ToJSON, TraverseState } from '@rimbu/common';
import { Reducer } from '@rimbu/common';

@@ -234,4 +234,4 @@ import { FastIterable, Stream, Streamable, StreamSource } from '@rimbu/stream';

interface Types extends KeyValue {
normal: VariantMapBase<this['_K'], this['_V']>;
nonEmpty: VariantMapBase.NonEmpty<this['_K'], this['_V']>;
readonly normal: VariantMapBase<this['_K'], this['_V']>;
readonly nonEmpty: VariantMapBase.NonEmpty<this['_K'], this['_V']>;
}

@@ -253,3 +253,3 @@ }

*/
set: (key: K, value: V) => WithKeyValue<Tp, K, V>['nonEmpty'];
set(key: K, value: V): WithKeyValue<Tp, K, V>['nonEmpty'];
/**

@@ -262,3 +262,3 @@ * Returns the collection with given `entry` added.

*/
addEntry: (entry: readonly [K, V]) => WithKeyValue<Tp, K, V>['nonEmpty'];
addEntry(entry: readonly [K, V]): WithKeyValue<Tp, K, V>['nonEmpty'];
/**

@@ -270,6 +270,4 @@ * Returns the collection with the entries from the given `StreamSource` `entries` added.

*/
addEntries: {
(entries: StreamSource.NonEmpty<readonly [K, V]>): WithKeyValue<Tp, K, V>['nonEmpty'];
(entries: StreamSource<readonly [K, V]>): WithKeyValue<Tp, K, V>['normal'];
};
addEntries(entries: StreamSource.NonEmpty<readonly [K, V]>): WithKeyValue<Tp, K, V>['nonEmpty'];
addEntries(entries: StreamSource<readonly [K, V]>): WithKeyValue<Tp, K, V>['normal'];
/**

@@ -297,6 +295,6 @@ * Returns the collection with the given `atKey` key modified according to given `options`.

*/
modifyAt: (atKey: K, options: {
modifyAt(atKey: K, options: {
ifNew?: OptLazyOr<V, Token>;
ifExists?: (currentEntry: V, remove: Token) => V | Token;
}) => WithKeyValue<Tp, K, V>['normal'];
ifExists?: <V2 extends V = V>(currentEntry: V & V2, remove: Token) => V | Token;
}): WithKeyValue<Tp, K, V>['normal'];
/**

@@ -315,3 +313,3 @@ * Returns the collection where the value associated with given `key` is updated with the given `update` value or update function.

*/
updateAt<UK = K>(key: RelatedTo<K, UK>, update: Update<V>): WithKeyValue<Tp, K, V>['normal'];
updateAt<UK = K>(key: RelatedTo<K, UK>, update: RMapBase.Update<V>): WithKeyValue<Tp, K, V>['normal'];
/**

@@ -322,115 +320,6 @@ * Returns a builder object containing the entries of this collection.

*/
toBuilder: () => WithKeyValue<Tp, K, V>['builder'];
/**
* Returns the same Map with an extended value type.
* @typeparam V2 - a type that extends V that defines the new value type
* @example
* const m = HashMap.of([1, 'a'], [2, 'b'])
* m.extendValues<number | string>
* // => type: HashMap.NonEmpty<number, number | string>
* m.extendValues<boolean>
* // => type: HashMap.NonEmpty<number, never>
*/
extendValues: <V2>() => WithKeyValue<Tp, K, SuperOf<V2, V>>['normal'];
/**
* Returns a Map containing all keys from this map and all the given `sources` key-value stream sources,
* and as values tuples of all the corresponding values for each key. If a source doesn't have a key,
* the tuple will be filled with the given `fillValue`.
* @typeparam O - the type of the fill value
* @typeparam I - the array of input source value types
* @param fillValue - the value to use for the result tuple if a source does not have a certain key
* @param sources - a non-empty set of StreamSouces containing tuples of keys and values
* @example
* const m = HashMap.of([1, 'a'], [2, 'b'])
* const m2 = m.mergeAll('none', [[2, true]], HashMap.of([3, 15]))
* // type of m2: HashMap<number, [string, boolean | string, number | string]>
* console.log(m2.toArray())
* // => [[1, ['a', 'none', 'none']], [2, ['b', true, 'none']], [3, ['none', 'none', 15]]]
*/
mergeAll: {
<O, I extends readonly [unknown, ...unknown[]]>(fillValue: O, ...sources: {
[KT in keyof I]: StreamSource.NonEmpty<readonly [K, I[KT]]>;
}): (Tp & KeyValue<K, [V | O, ...{
[KT in keyof I]: I[KT] | O;
}]>)['nonEmpty'];
<O, I extends readonly [unknown, ...unknown[]]>(fillValue: O, ...sources: {
[KT in keyof I]: StreamSource<readonly [K, I[KT]]>;
}): (Tp & KeyValue<K, [V | O, ...{
[KT in keyof I]: I[KT] | O;
}]>)['normal'];
};
/**
* Returns a Map containing all keys from this map and all the given `sources` key-value stream sources,
* and as values the result of applying the given `mergeFun` to the key and all the corresponding values for each key. If a source doesn't have a key,
* the given tuple will be filled with the given `fillValue`.
* @typeparam O - the type of the fill value
* @typeparam I - the array of input source value types
* @param fillValue - the value to use for the result tuple if a source does not have a certain key
* @param sources - a non-empty set of StreamSouces containing tuples of keys and values
* @example
* const m = HashMap.of([1, 'a'], [2, 'b'])
* const m2 = m.mergeAllWith(
* 'q',
* (key, v1, v2, v3) => `${key}${v1}${v2}${v3}`,
* [[2, 'c']],
* HashMap.of([3, 'd'])
* )
* // type of m2: HashMap<number, string>
* console.log(m2.toArray())
* // => [[1, '1aqq'], [2, '2bcq'], [3, '3qqd']]
*/
mergeAllWith: {
<R, O, I extends readonly [unknown, ...unknown[]]>(fillValue: O, mergeFun: (key: K, value: V | O, ...values: {
[KT in keyof I]: I[KT] | O;
}) => R, ...sources: {
[KT in keyof I]: StreamSource.NonEmpty<readonly [K, I[KT]]>;
}): (Tp & KeyValue<K, R>)['nonEmpty'];
<R, O, I extends readonly [unknown, ...unknown[]]>(fillValue: O, mergeFun: (key: K, value: V | O, ...values: {
[KT in keyof I]: I[KT] | O;
}) => R, ...sources: {
[KT in keyof I]: StreamSource<readonly [K, I[KT]]>;
}): (Tp & KeyValue<K, R>)['normal'];
};
/**
* Returns a Map containing the common keys from this map and all the given `sources` key-value stream sources,
* and as values tuples of all the corresponding values for each common key. If a source doesn't have a key,
* the key will be skipped.
* @typeparam I - the array of input source value types
* @param sources - a non-empty set of StreamSouces containing tuples of keys and values
* @example
* const m = HashMap.of([1, 'a'], [2, 'b'])
* const m2 = m.merge([[2, true]], HashMap.of([2, 15]))
* // type of m2: HashMap<number, [string, boolean, number]>
* console.log(m2.toArray())
* // => [[2, ['b', true, 15]]]
*/
merge: <I extends readonly [unknown, ...unknown[]]>(...sources: {
[KT in keyof I]: StreamSource<readonly [K, I[KT]]>;
}) => (Tp & KeyValue<K, [V, ...{
[KT in keyof I]: I[KT];
}]>)['normal'];
/**
* Returns a Map containing the common keys from this map and all the given `sources` key-value stream sources,
* and as values the result of applying given `mergeFun` to the key and values of all the corresponding values for each common key.
* If a source doesn't have a key, the key will be skipped.
* @typeparam I - the array of input source value types
* @param mergeFun - a function taking the key and values from this map and all sources corresponding to the key, and
* returning a value for the resulting Map.
* @param sources - a non-empty set of StreamSouces containing tuples of keys and values
* @example
* const m = HashMap.of([1, 'a'], [2, 'b'])
* const m2 = m.merge(
* (key, v1, v2) => `${key}${v1}${v2}`,
* [[2, true]],
* HashMap.of([2, 15])
* )
* // type of m2: HashMap<number, string>
* console.log(m2.toArray())
* // => [[2, '2true15']]
*/
mergeWith: <R, I extends readonly [unknown, ...unknown[]]>(mergeFun: (key: K, ...values: [V, ...I]) => R, ...sources: {
[KT in keyof I]: StreamSource<readonly [K, I[KT]]>;
}) => (Tp & KeyValue<K, R>)['normal'];
toBuilder(): WithKeyValue<Tp, K, V>['builder'];
}
export declare namespace RMapBase {
type Update<V> = V | (<V2 extends V>(value: V & V2) => V);
interface NonEmpty<K, V, Tp extends RMapBase.Types = RMapBase.Types> extends VariantMapBase.NonEmpty<K, V, Tp>, Omit<RMapBase<K, V, Tp>, keyof VariantMapBase.NonEmpty<any, any, any>>, Streamable.NonEmpty<readonly [K, V]> {

@@ -449,5 +338,3 @@ /**

*/
addEntries: {
(entries: StreamSource<readonly [K, V]>): WithKeyValue<Tp, K, V>['nonEmpty'];
};
addEntries(entries: StreamSource<readonly [K, V]>): WithKeyValue<Tp, K, V>['nonEmpty'];
/**

@@ -466,15 +353,63 @@ * Returns the collection where the value associated with given `key` is updated with the given `update` value or update function.

*/
updateAt<UK = K>(key: RelatedTo<K, UK>, update: Update<V>): WithKeyValue<Tp, K, V>['nonEmpty'];
updateAt<UK = K>(key: RelatedTo<K, UK>, update: RMapBase.Update<V>): WithKeyValue<Tp, K, V>['nonEmpty'];
}
/**
* The map's Context instance that serves as a factory for all related immutable instances and builders.
*/
interface Context<UK, Tp extends RMapBase.Types = RMapBase.Types> {
readonly _fixedKeyType: (key: UK) => never;
/**
* Returns the same Map with an extended value type.
* @typeparam V2 - a type that extends V that defines the new value type
* A string tag defining the specific collection type
* @example
* const m = HashMap.of([1, 'a'], [2, 'b'])
* m.extendValues<number | string>
* // => type: HashMap.NonEmpty<number, number | string>
* m.extendValues<boolean>
* // => type: HashMap.NonEmpty<number, never>
* HashMap.defaultContext().typeTag // => 'HashMap'
*/
extendValues: <V2>() => WithKeyValue<Tp, K, SuperOf<V2, V>>['nonEmpty'];
readonly typeTag: string;
readonly _types: Tp;
/**
* Returns true if given `obj` could be a valid key in this Context.
* @param obj - the object to check
* @example
* HashMap.defaultContext().isValidKey(1) // => true
*/
isValidKey(obj: any): obj is UK;
/**
* Returns the (singleton) empty instance of this type and context with given key and value types.
* @example
* HashMap.empty<number, string>() // => HashMap<number, string>
* HashMap.empty<string, boolean>() // => HashMap<string, boolean>
*/
empty<K extends UK, V>(): WithKeyValue<Tp, K, V>['normal'];
/**
* Returns an immutable map of this collection type and context, containing the given `entries`.
* @param entries - a non-empty array of key-value entries
* @example
* HashMap.of([1, 'a'], [2, 'b']) // => HashMap.NonEmpty<number, string>
*/
of<K extends UK, V>(...entries: ArrayNonEmpty<readonly [K, V]>): WithKeyValue<Tp, K, V>['nonEmpty'];
/**
* Returns an immutable map of this type and context, containing the entries in the given `sources` `StreamSource` instances.
* @param sources - an array of `StreamSource` instances containing key-value entries
* @example
* HashMap.from([[1, 'a'], [2, 'b']]) // => HashMap.NonEmpty<number, string>
*/
from<K extends UK, V>(...sources: ArrayNonEmpty<StreamSource.NonEmpty<readonly [K, V]>>): WithKeyValue<Tp, K, V>['nonEmpty'];
from<K, V>(...sources: ArrayNonEmpty<StreamSource<readonly [K, V]>>): WithKeyValue<Tp, K, V>['normal'];
/**
* Returns an empty builder instance for this type of collection and context.
* @example
* HashMap.builder<number, string>() // => HashMap.Builder<number, string>
*/
builder<K extends UK, V>(): WithKeyValue<Tp, K, V>['builder'];
/**
* Returns a `Reducer` that adds received tuples to an RMap and returns the RMap as a result. When a `source` is given,
* the reducer will first create an RMap from the source, and then add tuples to it.
* @param source - (optional) an initial source of tuples to add to
* @example
* const someSource = HashMap.of([1, 'a'], [2, 'b']);
* const result = Stream.of([1, 'c'], [3, 'a']).reduce(HashMap.reducer(someSource))
* result.toArray() // => [[1, 'c'], [2, 'b'], [3, 'a']]
* @note uses a builder under the hood. If the given `source` is an RMap in the same context, it will directly call `.toBuilder()`.
*/
reducer<K extends UK, V>(source?: StreamSource<readonly [K, V]>): Reducer<readonly [K, V], WithKeyValue<Tp, K, V>['normal']>;
/**
* Returns a Map containing all keys from this map and all the given `sources` key-value stream sources,

@@ -494,7 +429,12 @@ * and as values tuples of all the corresponding values for each key. If a source doesn't have a key,

*/
mergeAll: <O, I extends readonly [unknown, ...unknown[]]>(fillValue: O, ...sources: {
mergeAll<O, I extends readonly [unknown, unknown, ...unknown[]], K extends UK>(fillValue: O, ...sources: {
[KT in keyof I]: StreamSource.NonEmpty<readonly [K, I[KT]]>;
} & unknown[]): WithKeyValue<Tp, K, {
[KT in keyof I]: I[KT] | O;
}>['nonEmpty'];
mergeAll<O, I extends readonly [unknown, unknown, ...unknown[]], K extends UK>(fillValue: O, ...sources: {
[KT in keyof I]: StreamSource<readonly [K, I[KT]]>;
}) => (Tp & KeyValue<K, [V | O, ...{
} & unknown[]): WithKeyValue<Tp, K, {
[KT in keyof I]: I[KT] | O;
}]>)['nonEmpty'];
}>['normal'];
/**

@@ -520,7 +460,12 @@ * Returns a Map containing all keys from this map and all the given `sources` key-value stream sources,

*/
mergeAllWith: <R, O, I extends readonly [unknown, ...unknown[]]>(fillValue: O, mergeFun: (key: K, value: V | O, ...values: {
mergeAllWith<I extends readonly [unknown, unknown, ...unknown[]], K extends UK>(...sources: {
[KT in keyof I]: StreamSource.NonEmpty<readonly [K, I[KT]]>;
} & unknown[]): <O, R>(fillValue: O, mergeFun: (key: K, ...values: {
[KT in keyof I]: I[KT] | O;
}) => R, ...sources: {
}) => R) => WithKeyValue<Tp, K, R>['nonEmpty'];
mergeAllWith<I extends readonly [unknown, unknown, ...unknown[]], K extends UK>(...sources: {
[KT in keyof I]: StreamSource<readonly [K, I[KT]]>;
}) => (Tp & KeyValue<K, R>)['nonEmpty'];
} & unknown[]): <O, R>(fillValue: O, mergeFun: (key: K, ...values: {
[KT in keyof I]: I[KT] | O;
}) => R) => WithKeyValue<Tp, K, R>['normal'];
/**

@@ -539,14 +484,12 @@ * Returns a Map containing the common keys from this map and all the given `sources` key-value stream sources,

*/
merge: {
<I extends readonly [unknown, ...unknown[]]>(...sources: {
[KT in keyof I]: StreamSource.NonEmpty<readonly [K, I[KT]]>;
}): (Tp & KeyValue<K, [V, ...{
[KT in keyof I]: I[KT];
}]>)['nonEmpty'];
<I extends readonly [unknown, ...unknown[]]>(...sources: {
[KT in keyof I]: StreamSource<readonly [K, I[KT]]>;
}): (Tp & KeyValue<K, [V, ...{
[KT in keyof I]: I[KT];
}]>)['normal'];
};
merge<K extends UK, I extends readonly [unknown, unknown, ...unknown[]]>(...sources: {
[KT in keyof I]: StreamSource.NonEmpty<readonly [K, I[KT]]>;
} & unknown[]): WithKeyValue<Tp, K, {
[KT in keyof I]: I[KT];
}>['nonEmpty'];
merge<K extends UK, I extends readonly [unknown, unknown, ...unknown[]]>(...sources: {
[KT in keyof I]: StreamSource<readonly [K, I[KT]]>;
} & unknown[]): WithKeyValue<Tp, K, {
[KT in keyof I]: I[KT];
}>['normal'];
/**

@@ -571,71 +514,9 @@ * Returns a Map containing the common keys from this map and all the given `sources` key-value stream sources,

*/
mergeWith: {
<R, I extends readonly [unknown, ...unknown[]]>(mergeFun: (key: K, ...values: [V, ...I]) => R, ...sources: {
[KT in keyof I]: StreamSource.NonEmpty<readonly [K, I[KT]]>;
}): (Tp & KeyValue<K, R>)['nonEmpty'];
<R, I extends readonly [unknown, ...unknown[]]>(mergeFun: (key: K, ...values: [V, ...I]) => R, ...sources: {
[KT in keyof I]: StreamSource<readonly [K, I[KT]]>;
}): (Tp & KeyValue<K, R>)['normal'];
};
mergeWith<I extends readonly [unknown, unknown, ...unknown[]], K extends UK>(...sources: {
[KT in keyof I]: StreamSource.NonEmpty<readonly [K, I[KT]]>;
} & unknown[]): <R>(mergeFun: (key: K, ...values: I) => R) => WithKeyValue<Tp, K, R>['nonEmpty'];
mergeWith<I extends readonly [unknown, unknown, ...unknown[]], K extends UK>(...sources: {
[KT in keyof I]: StreamSource<readonly [K, I[KT]]>;
} & unknown[]): <R>(mergeFun: (key: K, ...values: I) => R) => WithKeyValue<Tp, K, R>['normal'];
}
/**
* The map's Context instance that serves as a factory for all related immutable instances and builders.
*/
interface Context<UK, Tp extends RMapBase.Types = RMapBase.Types> {
/**
* A string tag defining the specific collection type
* @example
* HashMap.defaultContext().typeTag // => 'HashMap'
*/
readonly typeTag: string;
readonly _types: Tp;
/**
* Returns true if given `obj` could be a valid key in this Context.
* @param obj - the object to check
* @example
* HashMap.defaultContext().isValidKey(1) // => true
*/
isValidKey: (obj: any) => obj is UK;
/**
* Returns the (singleton) empty instance of this type and context with given key and value types.
* @example
* HashMap.empty<number, string>() // => HashMap<number, string>
* HashMap.empty<string, boolean>() // => HashMap<string, boolean>
*/
empty: <K extends UK, V>() => WithKeyValue<Tp, K, V>['normal'];
/**
* Returns an immutable map of this collection type and context, containing the given `entries`.
* @param entries - a non-empty array of key-value entries
* @example
* HashMap.of([1, 'a'], [2, 'b']) // => HashMap.NonEmpty<number, string>
*/
of: <K extends UK, V>(...entries: ArrayNonEmpty<readonly [K, V]>) => WithKeyValue<Tp, K, V>['nonEmpty'];
/**
* Returns an immutable map of this type and context, containing the entries in the given `sources` `StreamSource` instances.
* @param sources - an array of `StreamSource` instances containing key-value entries
* @example
* HashMap.from([[1, 'a'], [2, 'b']]) // => HashMap.NonEmpty<number, string>
*/
from: {
<K extends UK, V>(...sources: ArrayNonEmpty<StreamSource.NonEmpty<readonly [K, V]>>): WithKeyValue<Tp, K, V>['nonEmpty'];
<K, V>(...sources: ArrayNonEmpty<StreamSource<readonly [K, V]>>): WithKeyValue<Tp, K, V>['normal'];
};
/**
* Returns an empty builder instance for this type of collection and context.
* @example
* HashMap.builder<number, string>() // => HashMap.Builder<number, string>
*/
builder: <K extends UK, V>() => WithKeyValue<Tp, K, V>['builder'];
/**
* Returns a `Reducer` that adds received tuples to an RMap and returns the RMap as a result. When a `source` is given,
* the reducer will first create an RMap from the source, and then add tuples to it.
* @param source - (optional) an initial source of tuples to add to
* @example
* const someSource = HashMap.of([1, 'a'], [2, 'b']);
* const result = Stream.of([1, 'c'], [3, 'a']).reduce(HashMap.reducer(someSource))
* result.toArray() // => [[1, 'c'], [2, 'b'], [3, 'a']]
* @note uses a builder under the hood. If the given `source` is an RMap in the same context, it will directly call `.toBuilder()`.
*/
reducer: <K extends UK, V>(source?: StreamSource<readonly [K, V]>) => Reducer<readonly [K, V], WithKeyValue<Tp, K, V>['normal']>;
}
interface Builder<K, V, Tp extends RMapBase.Types = RMapBase.Types> {

@@ -708,3 +589,3 @@ /**

*/
addEntry: (entry: readonly [K, V]) => boolean;
addEntry(entry: readonly [K, V]): boolean;
/**

@@ -719,3 +600,3 @@ * Adds given `entries` to the builder.

*/
addEntries: (entries: StreamSource<readonly [K, V]>) => boolean;
addEntries(entries: StreamSource<readonly [K, V]>): boolean;
/**

@@ -731,3 +612,3 @@ * Associates given `key` with given `value` in the builder.

*/
set: (key: K, value: V) => boolean;
set(key: K, value: V): boolean;
/**

@@ -780,6 +661,6 @@ * Removes the entry with given `key` from the builder.

*/
modifyAt: (key: K, options: {
modifyAt(key: K, options: {
ifNew?: OptLazyOr<V, Token>;
ifExists?: (currentValue: V, remove: Token) => V | Token;
}) => boolean;
ifExists?: <V2 extends V = V>(currentValue: V & V2, remove: Token) => V | Token;
}): boolean;
/**

@@ -797,4 +678,4 @@ * Updates the value in the builder associated with given `key` according to given `update` value or function.

*/
updateAt(key: K, update: Update<V>): V | undefined;
updateAt<O>(key: K, update: Update<V>, otherwise: OptLazy<O>): V | O;
updateAt(key: K, update: RMapBase.Update<V>): V | undefined;
updateAt<O>(key: K, update: RMapBase.Update<V>, otherwise: OptLazy<O>): V | O;
/**

@@ -806,3 +687,3 @@ * Returns an immutable collection instance containing the entries in this builder.

*/
build: () => WithKeyValue<Tp, K, V>['normal'];
build(): WithKeyValue<Tp, K, V>['normal'];
/**

@@ -816,3 +697,3 @@ * Returns an immutable instance of the entries in this builder, with given `mapValues` function applied

*/
buildMapValues: <V2>(mapFun: (value: V, key: K) => V2) => (Tp & KeyValue<K, V2>)['normal'];
buildMapValues<V2>(mapFun: (value: V, key: K) => V2): (Tp & KeyValue<K, V2>)['normal'];
}

@@ -833,2 +714,3 @@ interface Types extends VariantMapBase.Types {

abstract builder: <K extends UK, V>() => WithKeyValue<Tp, K, V>['builder'];
_fixedKeyType: any;
get _types(): Tp;

@@ -839,17 +721,7 @@ empty: <K extends UK, V>() => WithKeyValue<Tp, K, V>["normal"];

reducer: <K extends UK, V>(source?: StreamSource<readonly [K, V]> | undefined) => Reducer<readonly [K, V], WithKeyValue<Tp, K, V>["normal"]>;
mergeAllWith<R, K, O, I extends readonly [unknown, unknown, ...unknown[]]>(fillValue: O, mergeFun: (key: K, ...values: {
[KT in keyof I]: I[KT] | O;
}) => R, ...sources: {
[KT in keyof I]: StreamSource<readonly [K, I[KT]]>;
}): any;
mergeAll<O, K, I extends readonly [unknown, unknown, ...unknown[]]>(fillValue: O, ...sources: {
[KT in keyof I]: StreamSource<readonly [K, I[KT]]>;
}): any;
mergeWith<R, K, I extends readonly [unknown, ...unknown[]]>(mergeFun: (key: K, ...values: I) => R, ...sources: {
[KT in keyof I]: StreamSource<readonly [K, I[KT]]>;
}): any;
merge<K, I extends readonly [unknown, ...unknown[]]>(...sources: {
[KT in keyof I]: StreamSource<readonly [K, I[KT]]>;
}): any;
mergeAllWith: any;
mergeAll: any;
mergeWith: any;
merge: any;
}
}

@@ -37,7 +37,7 @@ import type { Streamable } from '@rimbu/stream';

interface Types extends RMapBase.Types {
normal: RMap<this['_K'], this['_V']>;
nonEmpty: RMap.NonEmpty<this['_K'], this['_V']>;
context: RMap.Context<this['_K']>;
builder: RMap.Builder<this['_K'], this['_V']>;
readonly normal: RMap<this['_K'], this['_V']>;
readonly nonEmpty: RMap.NonEmpty<this['_K'], this['_V']>;
readonly context: RMap.Context<this['_K']>;
readonly builder: RMap.Builder<this['_K'], this['_V']>;
}
}

@@ -31,5 +31,5 @@ import type { Streamable } from '@rimbu/stream';

interface Types extends VariantMapBase.Types {
normal: VariantMap<this['_K'], this['_V']>;
nonEmpty: VariantMap.NonEmpty<this['_K'], this['_V']>;
readonly normal: VariantMap<this['_K'], this['_V']>;
readonly nonEmpty: VariantMap.NonEmpty<this['_K'], this['_V']>;
}
}

@@ -169,4 +169,4 @@ import type { ArrayNonEmpty, RelatedTo, ToJSON, TraverseState } from '@rimbu/common';

interface Types extends Elem {
normal: VariantSetBase<this['_T']>;
nonEmpty: VariantSetBase.NonEmpty<this['_T']>;
readonly normal: VariantSetBase<this['_T']>;
readonly nonEmpty: VariantSetBase.NonEmpty<this['_T']>;
}

@@ -185,3 +185,3 @@ }

*/
add: (value: T) => WithElem<Tp, T>['nonEmpty'];
add(value: T): WithElem<Tp, T>['nonEmpty'];
/**

@@ -193,6 +193,4 @@ * Returns the collection with the values in given `values` `StreamSource` added.

*/
addAll: {
(values: StreamSource.NonEmpty<T>): WithElem<Tp, T>['nonEmpty'];
(values: StreamSource<T>): WithElem<Tp, T>['normal'];
};
addAll(values: StreamSource.NonEmpty<T>): WithElem<Tp, T>['nonEmpty'];
addAll(values: StreamSource<T>): WithElem<Tp, T>['normal'];
/**

@@ -206,6 +204,4 @@ * Returns a collection containing all values from this collection and all values of given

*/
union: {
(other: StreamSource.NonEmpty<T>): WithElem<Tp, T>['nonEmpty'];
(other: StreamSource<T>): WithElem<Tp, T>['normal'];
};
union(other: StreamSource.NonEmpty<T>): WithElem<Tp, T>['nonEmpty'];
union(other: StreamSource<T>): WithElem<Tp, T>['normal'];
/**

@@ -219,3 +215,3 @@ * Returns a collection of the values that are either in this collection or in the `other` `StreamSource`, but

*/
symDifference: (other: StreamSource<T>) => WithElem<Tp, T>['normal'];
symDifference(other: StreamSource<T>): WithElem<Tp, T>['normal'];
/**

@@ -226,3 +222,3 @@ * Returns a builder object containing the values of this collection.

*/
toBuilder: () => WithElem<Tp, T>['builder'];
toBuilder(): WithElem<Tp, T>['builder'];
}

@@ -243,3 +239,3 @@ export declare namespace RSetBase {

*/
add: (value: T) => WithElem<Tp, T>['nonEmpty'];
add(value: T): WithElem<Tp, T>['nonEmpty'];
/**

@@ -251,3 +247,3 @@ * Returns the collection with the values in given `values` `StreamSource` added.

*/
addAll: (values: StreamSource<T>) => WithElem<Tp, T>['nonEmpty'];
addAll(values: StreamSource<T>): WithElem<Tp, T>['nonEmpty'];
/**

@@ -261,5 +257,6 @@ * Returns a collection containing all values from this collection and all values of given

*/
union: (other: StreamSource<T>) => WithElem<Tp, T>['nonEmpty'];
union(other: StreamSource<T>): WithElem<Tp, T>['nonEmpty'];
}
interface Context<UT, Tp extends RSetBase.Types = RSetBase.Types> {
readonly _fixedElementType: (element: UT) => never;
/**

@@ -278,3 +275,3 @@ * A string tag defining the specific collection type

*/
isValidValue: (value: any) => value is UT;
isValidValue(value: any): value is UT;
/**

@@ -286,3 +283,3 @@ * Returns the (singleton) empty instance of this type and context with given value type.

*/
empty: <T extends UT>() => WithElem<Tp, T>['normal'];
empty<T extends UT>(): WithElem<Tp, T>['normal'];
/**

@@ -294,3 +291,3 @@ * Returns an immutable set of this type and context, containing the given `values`.

*/
of: <T extends UT>(...values: ArrayNonEmpty<T>) => WithElem<Tp, T>['nonEmpty'];
of<T extends UT>(...values: ArrayNonEmpty<T>): WithElem<Tp, T>['nonEmpty'];
/**

@@ -302,6 +299,4 @@ * Returns an immutable set of this collection type and context, containing the given values in `source`.

*/
from: {
<T extends UT>(...sources: ArrayNonEmpty<StreamSource.NonEmpty<T>>): WithElem<Tp, T>['nonEmpty'];
<T extends UT>(...sources: ArrayNonEmpty<StreamSource<T>>): WithElem<Tp, T>['normal'];
};
from<T extends UT>(...sources: ArrayNonEmpty<StreamSource.NonEmpty<T>>): WithElem<Tp, T>['nonEmpty'];
from<T extends UT>(...sources: ArrayNonEmpty<StreamSource<T>>): WithElem<Tp, T>['normal'];
/**

@@ -312,3 +307,3 @@ * Returns an empty builder instance for this type of collection and context.

*/
builder: <T extends UT>() => WithElem<Tp, T>['builder'];
builder<T extends UT>(): WithElem<Tp, T>['builder'];
/**

@@ -324,3 +319,3 @@ * Returns a `Reducer` that appends received items to an RSet and returns the RSet as a result. When a `source` is given,

*/
reducer: <T>(source?: StreamSource<T>) => Reducer<T, WithElem<Tp, T>['normal']>;
reducer<T extends UT>(source?: StreamSource<T>): Reducer<T, WithElem<Tp, T>['normal']>;
}

@@ -360,3 +355,3 @@ interface Builder<T, Tp extends RSetBase.Types = RSetBase.Types> {

*/
add: (value: T) => boolean;
add(value: T): boolean;
/**

@@ -371,3 +366,3 @@ * Adds the values in given `values` `StreamSource` to the builder.

*/
addAll: (values: StreamSource<T>) => boolean;
addAll(values: StreamSource<T>): boolean;
/**

@@ -414,3 +409,3 @@ * Remove the given `value` from the builder.

*/
build: () => WithElem<Tp, T>['normal'];
build(): WithElem<Tp, T>['normal'];
}

@@ -430,2 +425,3 @@ interface Types extends VariantSetBase.Types {

abstract builder<T extends UT>(): WithElem<Tp, T>['builder'];
readonly _fixedElementType: any;
get _types(): Tp;

@@ -432,0 +428,0 @@ empty: <T extends UT>() => WithElem<Tp, T>["normal"];

@@ -32,7 +32,7 @@ import type { Streamable } from '@rimbu/stream';

interface Types extends RSetBase.Types {
normal: RSet<this['_T']>;
nonEmpty: RSet.NonEmpty<this['_T']>;
context: RSet.Context<this['_T']>;
builder: RSet.Builder<this['_T']>;
readonly normal: RSet<this['_T']>;
readonly nonEmpty: RSet.NonEmpty<this['_T']>;
readonly context: RSet.Context<this['_T']>;
readonly builder: RSet.Builder<this['_T']>;
}
}

@@ -27,5 +27,5 @@ import type { Streamable } from '@rimbu/stream';

interface Types extends VariantSetBase.Types {
normal: VariantSet<this['_T']>;
nonEmpty: VariantSet.NonEmpty<this['_T']>;
readonly normal: VariantSet<this['_T']>;
readonly nonEmpty: VariantSet.NonEmpty<this['_T']>;
}
}
{
"name": "@rimbu/collection-types",
"version": "0.7.5",
"version": "0.8.0",
"description": "Type definitions for the basic generic Rimbu collections",

@@ -55,5 +55,5 @@ "keywords": [

"dependencies": {
"@rimbu/base": "^0.6.7",
"@rimbu/common": "^0.7.5",
"@rimbu/stream": "^0.7.5",
"@rimbu/base": "^0.7.0",
"@rimbu/common": "^0.8.0",
"@rimbu/stream": "^0.8.0",
"tslib": "^2.3.1"

@@ -67,3 +67,3 @@ },

},
"gitHead": "20739fd0c0d5c565eeecd3e266dd51f893e8d67c"
"gitHead": "c321aa32b1c5fd8ca8b7fb1c26bd4f7bbf3ef70d"
}

@@ -53,15 +53,2 @@ <p align="center">

## Recommended `tsconfig.json` settings
Rimbu uses advanced and recursive typing, potentially making the TypeScript compiler quite slow in some cases, or causing infinite recursion. It is recommended to set the following values in the `tsconfig.json` file of your project:
```json
{
"compilerOptions": {
"skipLibCheck": true,
"noStrictGenericChecks": true
}
}
```
## Author

@@ -68,0 +55,0 @@

@@ -7,6 +7,4 @@ import type { Token } from '@rimbu/base';

RelatedTo,
SuperOf,
ToJSON,
TraverseState,
Update,
} from '@rimbu/common';

@@ -269,4 +267,4 @@ import { Reducer } from '@rimbu/common';

export interface Types extends KeyValue {
normal: VariantMapBase<this['_K'], this['_V']>;
nonEmpty: VariantMapBase.NonEmpty<this['_K'], this['_V']>;
readonly normal: VariantMapBase<this['_K'], this['_V']>;
readonly nonEmpty: VariantMapBase.NonEmpty<this['_K'], this['_V']>;
}

@@ -290,3 +288,3 @@ }

*/
set: (key: K, value: V) => WithKeyValue<Tp, K, V>['nonEmpty'];
set(key: K, value: V): WithKeyValue<Tp, K, V>['nonEmpty'];
/**

@@ -299,3 +297,3 @@ * Returns the collection with given `entry` added.

*/
addEntry: (entry: readonly [K, V]) => WithKeyValue<Tp, K, V>['nonEmpty'];
addEntry(entry: readonly [K, V]): WithKeyValue<Tp, K, V>['nonEmpty'];
/**

@@ -307,10 +305,8 @@ * Returns the collection with the entries from the given `StreamSource` `entries` added.

*/
addEntries: {
(entries: StreamSource.NonEmpty<readonly [K, V]>): WithKeyValue<
Tp,
K,
V
>['nonEmpty'];
(entries: StreamSource<readonly [K, V]>): WithKeyValue<Tp, K, V>['normal'];
};
addEntries(
entries: StreamSource.NonEmpty<readonly [K, V]>
): WithKeyValue<Tp, K, V>['nonEmpty'];
addEntries(
entries: StreamSource<readonly [K, V]>
): WithKeyValue<Tp, K, V>['normal'];
/**

@@ -338,9 +334,12 @@ * Returns the collection with the given `atKey` key modified according to given `options`.

*/
modifyAt: (
modifyAt(
atKey: K,
options: {
ifNew?: OptLazyOr<V, Token>;
ifExists?: (currentEntry: V, remove: Token) => V | Token;
ifExists?: <V2 extends V = V>(
currentEntry: V & V2,
remove: Token
) => V | Token;
}
) => WithKeyValue<Tp, K, V>['normal'];
): WithKeyValue<Tp, K, V>['normal'];
/**

@@ -361,3 +360,3 @@ * Returns the collection where the value associated with given `key` is updated with the given `update` value or update function.

key: RelatedTo<K, UK>,
update: Update<V>
update: RMapBase.Update<V>
): WithKeyValue<Tp, K, V>['normal'];

@@ -369,126 +368,8 @@ /**

*/
toBuilder: () => WithKeyValue<Tp, K, V>['builder'];
/**
* Returns the same Map with an extended value type.
* @typeparam V2 - a type that extends V that defines the new value type
* @example
* const m = HashMap.of([1, 'a'], [2, 'b'])
* m.extendValues<number | string>
* // => type: HashMap.NonEmpty<number, number | string>
* m.extendValues<boolean>
* // => type: HashMap.NonEmpty<number, never>
*/
extendValues: <V2>() => WithKeyValue<Tp, K, SuperOf<V2, V>>['normal'];
/**
* Returns a Map containing all keys from this map and all the given `sources` key-value stream sources,
* and as values tuples of all the corresponding values for each key. If a source doesn't have a key,
* the tuple will be filled with the given `fillValue`.
* @typeparam O - the type of the fill value
* @typeparam I - the array of input source value types
* @param fillValue - the value to use for the result tuple if a source does not have a certain key
* @param sources - a non-empty set of StreamSouces containing tuples of keys and values
* @example
* const m = HashMap.of([1, 'a'], [2, 'b'])
* const m2 = m.mergeAll('none', [[2, true]], HashMap.of([3, 15]))
* // type of m2: HashMap<number, [string, boolean | string, number | string]>
* console.log(m2.toArray())
* // => [[1, ['a', 'none', 'none']], [2, ['b', true, 'none']], [3, ['none', 'none', 15]]]
*/
mergeAll: {
<O, I extends readonly [unknown, ...unknown[]]>(
fillValue: O,
...sources: {
[KT in keyof I]: StreamSource.NonEmpty<readonly [K, I[KT]]>;
}
): (Tp &
KeyValue<K, [V | O, ...{ [KT in keyof I]: I[KT] | O }]>)['nonEmpty'];
<O, I extends readonly [unknown, ...unknown[]]>(
fillValue: O,
...sources: { [KT in keyof I]: StreamSource<readonly [K, I[KT]]> }
): (Tp & KeyValue<K, [V | O, ...{ [KT in keyof I]: I[KT] | O }]>)['normal'];
};
/**
* Returns a Map containing all keys from this map and all the given `sources` key-value stream sources,
* and as values the result of applying the given `mergeFun` to the key and all the corresponding values for each key. If a source doesn't have a key,
* the given tuple will be filled with the given `fillValue`.
* @typeparam O - the type of the fill value
* @typeparam I - the array of input source value types
* @param fillValue - the value to use for the result tuple if a source does not have a certain key
* @param sources - a non-empty set of StreamSouces containing tuples of keys and values
* @example
* const m = HashMap.of([1, 'a'], [2, 'b'])
* const m2 = m.mergeAllWith(
* 'q',
* (key, v1, v2, v3) => `${key}${v1}${v2}${v3}`,
* [[2, 'c']],
* HashMap.of([3, 'd'])
* )
* // type of m2: HashMap<number, string>
* console.log(m2.toArray())
* // => [[1, '1aqq'], [2, '2bcq'], [3, '3qqd']]
*/
mergeAllWith: {
<R, O, I extends readonly [unknown, ...unknown[]]>(
fillValue: O,
mergeFun: (
key: K,
value: V | O,
...values: { [KT in keyof I]: I[KT] | O }
) => R,
...sources: {
[KT in keyof I]: StreamSource.NonEmpty<readonly [K, I[KT]]>;
}
): (Tp & KeyValue<K, R>)['nonEmpty'];
<R, O, I extends readonly [unknown, ...unknown[]]>(
fillValue: O,
mergeFun: (
key: K,
value: V | O,
...values: { [KT in keyof I]: I[KT] | O }
) => R,
...sources: { [KT in keyof I]: StreamSource<readonly [K, I[KT]]> }
): (Tp & KeyValue<K, R>)['normal'];
};
/**
* Returns a Map containing the common keys from this map and all the given `sources` key-value stream sources,
* and as values tuples of all the corresponding values for each common key. If a source doesn't have a key,
* the key will be skipped.
* @typeparam I - the array of input source value types
* @param sources - a non-empty set of StreamSouces containing tuples of keys and values
* @example
* const m = HashMap.of([1, 'a'], [2, 'b'])
* const m2 = m.merge([[2, true]], HashMap.of([2, 15]))
* // type of m2: HashMap<number, [string, boolean, number]>
* console.log(m2.toArray())
* // => [[2, ['b', true, 15]]]
*/
merge: <I extends readonly [unknown, ...unknown[]]>(
...sources: { [KT in keyof I]: StreamSource<readonly [K, I[KT]]> }
) => (Tp & KeyValue<K, [V, ...{ [KT in keyof I]: I[KT] }]>)['normal'];
/**
* Returns a Map containing the common keys from this map and all the given `sources` key-value stream sources,
* and as values the result of applying given `mergeFun` to the key and values of all the corresponding values for each common key.
* If a source doesn't have a key, the key will be skipped.
* @typeparam I - the array of input source value types
* @param mergeFun - a function taking the key and values from this map and all sources corresponding to the key, and
* returning a value for the resulting Map.
* @param sources - a non-empty set of StreamSouces containing tuples of keys and values
* @example
* const m = HashMap.of([1, 'a'], [2, 'b'])
* const m2 = m.merge(
* (key, v1, v2) => `${key}${v1}${v2}`,
* [[2, true]],
* HashMap.of([2, 15])
* )
* // type of m2: HashMap<number, string>
* console.log(m2.toArray())
* // => [[2, '2true15']]
*/
mergeWith: <R, I extends readonly [unknown, ...unknown[]]>(
mergeFun: (key: K, ...values: [V, ...I]) => R,
...sources: { [KT in keyof I]: StreamSource<readonly [K, I[KT]]> }
) => (Tp & KeyValue<K, R>)['normal'];
toBuilder(): WithKeyValue<Tp, K, V>['builder'];
}
export namespace RMapBase {
export type Update<V> = V | (<V2 extends V>(value: V & V2) => V);
export interface NonEmpty<K, V, Tp extends RMapBase.Types = RMapBase.Types>

@@ -510,9 +391,5 @@ extends VariantMapBase.NonEmpty<K, V, Tp>,

*/
addEntries: {
(entries: StreamSource<readonly [K, V]>): WithKeyValue<
Tp,
K,
V
>['nonEmpty'];
};
addEntries(
entries: StreamSource<readonly [K, V]>
): WithKeyValue<Tp, K, V>['nonEmpty'];
/**

@@ -533,16 +410,76 @@ * Returns the collection where the value associated with given `key` is updated with the given `update` value or update function.

key: RelatedTo<K, UK>,
update: Update<V>
update: RMapBase.Update<V>
): WithKeyValue<Tp, K, V>['nonEmpty'];
}
/**
* The map's Context instance that serves as a factory for all related immutable instances and builders.
*/
export interface Context<UK, Tp extends RMapBase.Types = RMapBase.Types> {
readonly _fixedKeyType: (key: UK) => never;
/**
* Returns the same Map with an extended value type.
* @typeparam V2 - a type that extends V that defines the new value type
* A string tag defining the specific collection type
* @example
* const m = HashMap.of([1, 'a'], [2, 'b'])
* m.extendValues<number | string>
* // => type: HashMap.NonEmpty<number, number | string>
* m.extendValues<boolean>
* // => type: HashMap.NonEmpty<number, never>
* HashMap.defaultContext().typeTag // => 'HashMap'
*/
extendValues: <V2>() => WithKeyValue<Tp, K, SuperOf<V2, V>>['nonEmpty'];
readonly typeTag: string;
readonly _types: Tp;
/**
* Returns true if given `obj` could be a valid key in this Context.
* @param obj - the object to check
* @example
* HashMap.defaultContext().isValidKey(1) // => true
*/
isValidKey(obj: any): obj is UK;
/**
* Returns the (singleton) empty instance of this type and context with given key and value types.
* @example
* HashMap.empty<number, string>() // => HashMap<number, string>
* HashMap.empty<string, boolean>() // => HashMap<string, boolean>
*/
empty<K extends UK, V>(): WithKeyValue<Tp, K, V>['normal'];
/**
* Returns an immutable map of this collection type and context, containing the given `entries`.
* @param entries - a non-empty array of key-value entries
* @example
* HashMap.of([1, 'a'], [2, 'b']) // => HashMap.NonEmpty<number, string>
*/
of<K extends UK, V>(
...entries: ArrayNonEmpty<readonly [K, V]>
): WithKeyValue<Tp, K, V>['nonEmpty'];
/**
* Returns an immutable map of this type and context, containing the entries in the given `sources` `StreamSource` instances.
* @param sources - an array of `StreamSource` instances containing key-value entries
* @example
* HashMap.from([[1, 'a'], [2, 'b']]) // => HashMap.NonEmpty<number, string>
*/
from<K extends UK, V>(
...sources: ArrayNonEmpty<StreamSource.NonEmpty<readonly [K, V]>>
): WithKeyValue<Tp, K, V>['nonEmpty'];
from<K, V>(
...sources: ArrayNonEmpty<StreamSource<readonly [K, V]>>
): WithKeyValue<Tp, K, V>['normal'];
/**
* Returns an empty builder instance for this type of collection and context.
* @example
* HashMap.builder<number, string>() // => HashMap.Builder<number, string>
*/
builder<K extends UK, V>(): WithKeyValue<Tp, K, V>['builder'];
/**
* Returns a `Reducer` that adds received tuples to an RMap and returns the RMap as a result. When a `source` is given,
* the reducer will first create an RMap from the source, and then add tuples to it.
* @param source - (optional) an initial source of tuples to add to
* @example
* const someSource = HashMap.of([1, 'a'], [2, 'b']);
* const result = Stream.of([1, 'c'], [3, 'a']).reduce(HashMap.reducer(someSource))
* result.toArray() // => [[1, 'c'], [2, 'b'], [3, 'a']]
* @note uses a builder under the hood. If the given `source` is an RMap in the same context, it will directly call `.toBuilder()`.
*/
reducer<K extends UK, V>(
source?: StreamSource<readonly [K, V]>
): Reducer<readonly [K, V], WithKeyValue<Tp, K, V>['normal']>;
/**
* Returns a Map containing all keys from this map and all the given `sources` key-value stream sources,

@@ -562,7 +499,22 @@ * and as values tuples of all the corresponding values for each key. If a source doesn't have a key,

*/
mergeAll: <O, I extends readonly [unknown, ...unknown[]]>(
mergeAll<
O,
I extends readonly [unknown, unknown, ...unknown[]],
K extends UK
>(
fillValue: O,
...sources: { [KT in keyof I]: StreamSource<readonly [K, I[KT]]> }
) => (Tp &
KeyValue<K, [V | O, ...{ [KT in keyof I]: I[KT] | O }]>)['nonEmpty'];
...sources: {
[KT in keyof I]: StreamSource.NonEmpty<readonly [K, I[KT]]>;
} &
unknown[]
): WithKeyValue<Tp, K, { [KT in keyof I]: I[KT] | O }>['nonEmpty'];
mergeAll<
O,
I extends readonly [unknown, unknown, ...unknown[]],
K extends UK
>(
fillValue: O,
...sources: { [KT in keyof I]: StreamSource<readonly [K, I[KT]]> } &
unknown[]
): WithKeyValue<Tp, K, { [KT in keyof I]: I[KT] | O }>['normal'];
/**

@@ -588,11 +540,24 @@ * Returns a Map containing all keys from this map and all the given `sources` key-value stream sources,

*/
mergeAllWith: <R, O, I extends readonly [unknown, ...unknown[]]>(
mergeAllWith<
I extends readonly [unknown, unknown, ...unknown[]],
K extends UK
>(
...sources: {
[KT in keyof I]: StreamSource.NonEmpty<readonly [K, I[KT]]>;
} &
unknown[]
): <O, R>(
fillValue: O,
mergeFun: (
key: K,
value: V | O,
...values: { [KT in keyof I]: I[KT] | O }
) => R,
...sources: { [KT in keyof I]: StreamSource<readonly [K, I[KT]]> }
) => (Tp & KeyValue<K, R>)['nonEmpty'];
mergeFun: (key: K, ...values: { [KT in keyof I]: I[KT] | O }) => R
) => WithKeyValue<Tp, K, R>['nonEmpty'];
mergeAllWith<
I extends readonly [unknown, unknown, ...unknown[]],
K extends UK
>(
...sources: { [KT in keyof I]: StreamSource<readonly [K, I[KT]]> } &
unknown[]
): <O, R>(
fillValue: O,
mergeFun: (key: K, ...values: { [KT in keyof I]: I[KT] | O }) => R
) => WithKeyValue<Tp, K, R>['normal'];
/**

@@ -611,12 +576,12 @@ * Returns a Map containing the common keys from this map and all the given `sources` key-value stream sources,

*/
merge: {
<I extends readonly [unknown, ...unknown[]]>(
...sources: {
[KT in keyof I]: StreamSource.NonEmpty<readonly [K, I[KT]]>;
}
): (Tp & KeyValue<K, [V, ...{ [KT in keyof I]: I[KT] }]>)['nonEmpty'];
<I extends readonly [unknown, ...unknown[]]>(
...sources: { [KT in keyof I]: StreamSource<readonly [K, I[KT]]> }
): (Tp & KeyValue<K, [V, ...{ [KT in keyof I]: I[KT] }]>)['normal'];
};
merge<K extends UK, I extends readonly [unknown, unknown, ...unknown[]]>(
...sources: {
[KT in keyof I]: StreamSource.NonEmpty<readonly [K, I[KT]]>;
} &
unknown[]
): WithKeyValue<Tp, K, { [KT in keyof I]: I[KT] }>['nonEmpty'];
merge<K extends UK, I extends readonly [unknown, unknown, ...unknown[]]>(
...sources: { [KT in keyof I]: StreamSource<readonly [K, I[KT]]> } &
unknown[]
): WithKeyValue<Tp, K, { [KT in keyof I]: I[KT] }>['normal'];
/**

@@ -641,87 +606,24 @@ * Returns a Map containing the common keys from this map and all the given `sources` key-value stream sources,

*/
mergeWith: {
<R, I extends readonly [unknown, ...unknown[]]>(
mergeFun: (key: K, ...values: [V, ...I]) => R,
...sources: {
[KT in keyof I]: StreamSource.NonEmpty<readonly [K, I[KT]]>;
}
): (Tp & KeyValue<K, R>)['nonEmpty'];
<R, I extends readonly [unknown, ...unknown[]]>(
mergeFun: (key: K, ...values: [V, ...I]) => R,
...sources: { [KT in keyof I]: StreamSource<readonly [K, I[KT]]> }
): (Tp & KeyValue<K, R>)['normal'];
};
mergeWith<
I extends readonly [unknown, unknown, ...unknown[]],
K extends UK
>(
...sources: {
[KT in keyof I]: StreamSource.NonEmpty<readonly [K, I[KT]]>;
} &
unknown[]
): <R>(
mergeFun: (key: K, ...values: I) => R
) => WithKeyValue<Tp, K, R>['nonEmpty'];
mergeWith<
I extends readonly [unknown, unknown, ...unknown[]],
K extends UK
>(
...sources: { [KT in keyof I]: StreamSource<readonly [K, I[KT]]> } &
unknown[]
): <R>(
mergeFun: (key: K, ...values: I) => R
) => WithKeyValue<Tp, K, R>['normal'];
}
/**
* The map's Context instance that serves as a factory for all related immutable instances and builders.
*/
export interface Context<UK, Tp extends RMapBase.Types = RMapBase.Types> {
/**
* A string tag defining the specific collection type
* @example
* HashMap.defaultContext().typeTag // => 'HashMap'
*/
readonly typeTag: string;
readonly _types: Tp;
/**
* Returns true if given `obj` could be a valid key in this Context.
* @param obj - the object to check
* @example
* HashMap.defaultContext().isValidKey(1) // => true
*/
isValidKey: (obj: any) => obj is UK;
/**
* Returns the (singleton) empty instance of this type and context with given key and value types.
* @example
* HashMap.empty<number, string>() // => HashMap<number, string>
* HashMap.empty<string, boolean>() // => HashMap<string, boolean>
*/
empty: <K extends UK, V>() => WithKeyValue<Tp, K, V>['normal'];
/**
* Returns an immutable map of this collection type and context, containing the given `entries`.
* @param entries - a non-empty array of key-value entries
* @example
* HashMap.of([1, 'a'], [2, 'b']) // => HashMap.NonEmpty<number, string>
*/
of: <K extends UK, V>(
...entries: ArrayNonEmpty<readonly [K, V]>
) => WithKeyValue<Tp, K, V>['nonEmpty'];
/**
* Returns an immutable map of this type and context, containing the entries in the given `sources` `StreamSource` instances.
* @param sources - an array of `StreamSource` instances containing key-value entries
* @example
* HashMap.from([[1, 'a'], [2, 'b']]) // => HashMap.NonEmpty<number, string>
*/
from: {
<K extends UK, V>(
...sources: ArrayNonEmpty<StreamSource.NonEmpty<readonly [K, V]>>
): WithKeyValue<Tp, K, V>['nonEmpty'];
<K, V>(
...sources: ArrayNonEmpty<StreamSource<readonly [K, V]>>
): WithKeyValue<Tp, K, V>['normal'];
};
/**
* Returns an empty builder instance for this type of collection and context.
* @example
* HashMap.builder<number, string>() // => HashMap.Builder<number, string>
*/
builder: <K extends UK, V>() => WithKeyValue<Tp, K, V>['builder'];
/**
* Returns a `Reducer` that adds received tuples to an RMap and returns the RMap as a result. When a `source` is given,
* the reducer will first create an RMap from the source, and then add tuples to it.
* @param source - (optional) an initial source of tuples to add to
* @example
* const someSource = HashMap.of([1, 'a'], [2, 'b']);
* const result = Stream.of([1, 'c'], [3, 'a']).reduce(HashMap.reducer(someSource))
* result.toArray() // => [[1, 'c'], [2, 'b'], [3, 'a']]
* @note uses a builder under the hood. If the given `source` is an RMap in the same context, it will directly call `.toBuilder()`.
*/
reducer: <K extends UK, V>(
source?: StreamSource<readonly [K, V]>
) => Reducer<readonly [K, V], WithKeyValue<Tp, K, V>['normal']>;
}
export interface Builder<K, V, Tp extends RMapBase.Types = RMapBase.Types> {

@@ -797,3 +699,3 @@ /**

*/
addEntry: (entry: readonly [K, V]) => boolean;
addEntry(entry: readonly [K, V]): boolean;
/**

@@ -808,3 +710,3 @@ * Adds given `entries` to the builder.

*/
addEntries: (entries: StreamSource<readonly [K, V]>) => boolean;
addEntries(entries: StreamSource<readonly [K, V]>): boolean;
/**

@@ -820,3 +722,3 @@ * Associates given `key` with given `value` in the builder.

*/
set: (key: K, value: V) => boolean;
set(key: K, value: V): boolean;
/**

@@ -869,9 +771,12 @@ * Removes the entry with given `key` from the builder.

*/
modifyAt: (
modifyAt(
key: K,
options: {
ifNew?: OptLazyOr<V, Token>;
ifExists?: (currentValue: V, remove: Token) => V | Token;
ifExists?: <V2 extends V = V>(
currentValue: V & V2,
remove: Token
) => V | Token;
}
) => boolean;
): boolean;
/**

@@ -889,4 +794,8 @@ * Updates the value in the builder associated with given `key` according to given `update` value or function.

*/
updateAt(key: K, update: Update<V>): V | undefined;
updateAt<O>(key: K, update: Update<V>, otherwise: OptLazy<O>): V | O;
updateAt(key: K, update: RMapBase.Update<V>): V | undefined;
updateAt<O>(
key: K,
update: RMapBase.Update<V>,
otherwise: OptLazy<O>
): V | O;
/**

@@ -898,3 +807,3 @@ * Returns an immutable collection instance containing the entries in this builder.

*/
build: () => WithKeyValue<Tp, K, V>['normal'];
build(): WithKeyValue<Tp, K, V>['normal'];
/**

@@ -908,5 +817,5 @@ * Returns an immutable instance of the entries in this builder, with given `mapValues` function applied

*/
buildMapValues: <V2>(
buildMapValues<V2>(
mapFun: (value: V, key: K) => V2
) => (Tp & KeyValue<K, V2>)['normal'];
): (Tp & KeyValue<K, V2>)['normal'];
}

@@ -937,2 +846,4 @@

_fixedKeyType!: any;
get _types(): Tp {

@@ -999,91 +910,114 @@ return undefined as any;

mergeAllWith<R, K, O, I extends readonly [unknown, unknown, ...unknown[]]>(
fillValue: O,
mergeFun: (key: K, ...values: { [KT in keyof I]: I[KT] | O }) => R,
mergeAllWith: any = <
K,
I extends readonly [unknown, unknown, ...unknown[]]
>(
...sources: { [KT in keyof I]: StreamSource<readonly [K, I[KT]]> }
): any {
const builder = this.builder() as unknown as RMapBase.Builder<
K,
unknown[]
>;
): any => {
return <O, R>(
fillValue: O,
mergeFun: (key: K, ...values: { [KT in keyof I]: I[KT] | O }) => R
): any => {
const builder = this.builder() as unknown as RMapBase.Builder<
K,
unknown[]
>;
let i = -1;
const length = sources.length;
let i = -1;
const length = sources.length;
while (++i < sources.length) {
let entry: readonly [K, unknown] | undefined;
const iter = Stream.from(sources[i])[Symbol.iterator]();
while (++i < sources.length) {
let entry: readonly [K, unknown] | undefined;
const iter = Stream.from(sources[i])[Symbol.iterator]();
while (undefined !== (entry = iter.fastNext())) {
const key = entry[0];
const value = entry[1];
while (undefined !== (entry = iter.fastNext())) {
const key = entry[0];
const value = entry[1];
const index = i;
const index = i;
builder.modifyAt(key, {
ifNew(): unknown[] {
const row = Array(length).fill(fillValue);
row[index] = value;
return row;
},
ifExists(row): unknown[] {
row[index] = value;
return row;
},
});
builder.modifyAt(key, {
ifNew(): unknown[] {
const row = Array(length).fill(fillValue);
row[index] = value;
return row;
},
ifExists(row): unknown[] {
row[index] = value;
return row;
},
});
}
}
}
return builder.buildMapValues((row, key) =>
mergeFun(key, ...(row as any))
);
}
return builder.buildMapValues((row, key) =>
mergeFun(key, ...(row as any))
);
};
};
mergeAll<O, K, I extends readonly [unknown, unknown, ...unknown[]]>(
mergeAll: any = <O, K, I extends readonly [unknown, unknown, ...unknown[]]>(
fillValue: O,
...sources: { [KT in keyof I]: StreamSource<readonly [K, I[KT]]> }
): any {
return this.mergeAllWith(
): any => {
return this.mergeAllWith(...sources)(
fillValue,
(key: any, ...values: unknown[]): I => values as any as I,
...(sources as any as [any, any, ...any[]])
(key: any, ...values: unknown[]): any => values
);
}
};
mergeWith<R, K, I extends readonly [unknown, ...unknown[]]>(
mergeFun: (key: K, ...values: I) => R,
mergeWith: any = <I extends readonly [unknown, ...unknown[]], K>(
...sources: { [KT in keyof I]: StreamSource<readonly [K, I[KT]]> }
): any {
if (Stream.from(sources).some(StreamSource.isEmptyInstance)) {
return this.empty();
}
): any => {
return <R>(mergeFun: (key: K, ...values: I) => R): any => {
if (Stream.from(sources).some(StreamSource.isEmptyInstance)) {
return this.empty();
}
const builder = this.builder() as unknown as RMapBase.Builder<
K,
unknown[]
>;
const builder = this.builder() as unknown as RMapBase.Builder<
K,
unknown[]
>;
let i = -1;
const length = sources.length;
let i = -1;
const length = sources.length;
while (++i < sources.length) {
while (++i < sources.length) {
let entry: readonly [K, unknown] | undefined;
const iter = Stream.from(sources[i])[Symbol.iterator]();
while (undefined !== (entry = iter.fastNext())) {
const key = entry[0];
const value = entry[1];
const index = i;
builder.modifyAt(key, {
ifNew(nothing): unknown[] | typeof nothing {
if (index > 0) return nothing;
const row = [value];
return row;
},
ifExists(row, remove): unknown[] | typeof remove {
if (row.length !== index) return remove;
row.push(value);
return row;
},
});
}
}
// remove all rows that are not full
const firstSource = sources[0];
let entry: readonly [K, unknown] | undefined;
const iter = Stream.from(sources[i])[Symbol.iterator]();
const iter = Stream.from(firstSource)[Symbol.iterator]();
while (undefined !== (entry = iter.fastNext())) {
const key = entry[0];
const value = entry[1];
const index = i;
builder.modifyAt(key, {
ifNew(nothing): unknown[] | typeof nothing {
if (index > 0) return nothing;
const row = [value];
return row;
},
ifExists(row, remove): unknown[] | typeof remove {
if (row.length !== index) return remove;
row.push(value);
if (row.length !== length) return remove;
return row;

@@ -1093,35 +1027,17 @@ },

}
}
// remove all rows that are not full
const firstSource = sources[0];
return builder.buildMapValues((row, key) =>
mergeFun(key, ...(row as any))
);
};
};
let entry: readonly [K, unknown] | undefined;
const iter = Stream.from(firstSource)[Symbol.iterator]();
while (undefined !== (entry = iter.fastNext())) {
const key = entry[0];
builder.modifyAt(key, {
ifExists(row, remove): unknown[] | typeof remove {
if (row.length !== length) return remove;
return row;
},
});
}
return builder.buildMapValues((row, key) =>
mergeFun(key, ...(row as any))
);
}
merge<K, I extends readonly [unknown, ...unknown[]]>(
merge: any = <K, I extends readonly [unknown, ...unknown[]]>(
...sources: { [KT in keyof I]: StreamSource<readonly [K, I[KT]]> }
): any {
return this.mergeWith(
(key: any, ...values: unknown[]): I => values as any as I,
...(sources as any as [any, any, ...any[]])
): any => {
return this.mergeWith(...sources)(
(key: any, ...values: unknown[]): any => values
);
}
};
}
}

@@ -40,7 +40,7 @@ import type { Streamable } from '@rimbu/stream';

export interface Types extends RMapBase.Types {
normal: RMap<this['_K'], this['_V']>;
nonEmpty: RMap.NonEmpty<this['_K'], this['_V']>;
context: RMap.Context<this['_K']>;
builder: RMap.Builder<this['_K'], this['_V']>;
readonly normal: RMap<this['_K'], this['_V']>;
readonly nonEmpty: RMap.NonEmpty<this['_K'], this['_V']>;
readonly context: RMap.Context<this['_K']>;
readonly builder: RMap.Builder<this['_K'], this['_V']>;
}
}

@@ -35,5 +35,5 @@ import type { Streamable } from '@rimbu/stream';

export interface Types extends VariantMapBase.Types {
normal: VariantMap<this['_K'], this['_V']>;
nonEmpty: VariantMap.NonEmpty<this['_K'], this['_V']>;
readonly normal: VariantMap<this['_K'], this['_V']>;
readonly nonEmpty: VariantMap.NonEmpty<this['_K'], this['_V']>;
}
}

@@ -195,4 +195,4 @@ import type {

export interface Types extends Elem {
normal: VariantSetBase<this['_T']>;
nonEmpty: VariantSetBase.NonEmpty<this['_T']>;
readonly normal: VariantSetBase<this['_T']>;
readonly nonEmpty: VariantSetBase.NonEmpty<this['_T']>;
}

@@ -213,3 +213,3 @@ }

*/
add: (value: T) => WithElem<Tp, T>['nonEmpty'];
add(value: T): WithElem<Tp, T>['nonEmpty'];
/**

@@ -221,6 +221,4 @@ * Returns the collection with the values in given `values` `StreamSource` added.

*/
addAll: {
(values: StreamSource.NonEmpty<T>): WithElem<Tp, T>['nonEmpty'];
(values: StreamSource<T>): WithElem<Tp, T>['normal'];
};
addAll(values: StreamSource.NonEmpty<T>): WithElem<Tp, T>['nonEmpty'];
addAll(values: StreamSource<T>): WithElem<Tp, T>['normal'];
/**

@@ -234,6 +232,4 @@ * Returns a collection containing all values from this collection and all values of given

*/
union: {
(other: StreamSource.NonEmpty<T>): WithElem<Tp, T>['nonEmpty'];
(other: StreamSource<T>): WithElem<Tp, T>['normal'];
};
union(other: StreamSource.NonEmpty<T>): WithElem<Tp, T>['nonEmpty'];
union(other: StreamSource<T>): WithElem<Tp, T>['normal'];
/**

@@ -247,3 +243,3 @@ * Returns a collection of the values that are either in this collection or in the `other` `StreamSource`, but

*/
symDifference: (other: StreamSource<T>) => WithElem<Tp, T>['normal'];
symDifference(other: StreamSource<T>): WithElem<Tp, T>['normal'];
/**

@@ -254,3 +250,3 @@ * Returns a builder object containing the values of this collection.

*/
toBuilder: () => WithElem<Tp, T>['builder'];
toBuilder(): WithElem<Tp, T>['builder'];
}

@@ -275,3 +271,3 @@

*/
add: (value: T) => WithElem<Tp, T>['nonEmpty'];
add(value: T): WithElem<Tp, T>['nonEmpty'];
/**

@@ -283,3 +279,3 @@ * Returns the collection with the values in given `values` `StreamSource` added.

*/
addAll: (values: StreamSource<T>) => WithElem<Tp, T>['nonEmpty'];
addAll(values: StreamSource<T>): WithElem<Tp, T>['nonEmpty'];
/**

@@ -293,6 +289,8 @@ * Returns a collection containing all values from this collection and all values of given

*/
union: (other: StreamSource<T>) => WithElem<Tp, T>['nonEmpty'];
union(other: StreamSource<T>): WithElem<Tp, T>['nonEmpty'];
}
export interface Context<UT, Tp extends RSetBase.Types = RSetBase.Types> {
readonly _fixedElementType: (element: UT) => never;
/**

@@ -313,3 +311,3 @@ * A string tag defining the specific collection type

*/
isValidValue: (value: any) => value is UT;
isValidValue(value: any): value is UT;
/**

@@ -321,3 +319,3 @@ * Returns the (singleton) empty instance of this type and context with given value type.

*/
empty: <T extends UT>() => WithElem<Tp, T>['normal'];
empty<T extends UT>(): WithElem<Tp, T>['normal'];
/**

@@ -329,5 +327,3 @@ * Returns an immutable set of this type and context, containing the given `values`.

*/
of: <T extends UT>(
...values: ArrayNonEmpty<T>
) => WithElem<Tp, T>['nonEmpty'];
of<T extends UT>(...values: ArrayNonEmpty<T>): WithElem<Tp, T>['nonEmpty'];
/**

@@ -339,11 +335,8 @@ * Returns an immutable set of this collection type and context, containing the given values in `source`.

*/
from: {
<T extends UT>(
...sources: ArrayNonEmpty<StreamSource.NonEmpty<T>>
): WithElem<Tp, T>['nonEmpty'];
<T extends UT>(...sources: ArrayNonEmpty<StreamSource<T>>): WithElem<
Tp,
T
>['normal'];
};
from<T extends UT>(
...sources: ArrayNonEmpty<StreamSource.NonEmpty<T>>
): WithElem<Tp, T>['nonEmpty'];
from<T extends UT>(
...sources: ArrayNonEmpty<StreamSource<T>>
): WithElem<Tp, T>['normal'];
/**

@@ -354,3 +347,3 @@ * Returns an empty builder instance for this type of collection and context.

*/
builder: <T extends UT>() => WithElem<Tp, T>['builder'];
builder<T extends UT>(): WithElem<Tp, T>['builder'];
/**

@@ -366,5 +359,5 @@ * Returns a `Reducer` that appends received items to an RSet and returns the RSet as a result. When a `source` is given,

*/
reducer: <T>(
reducer<T extends UT>(
source?: StreamSource<T>
) => Reducer<T, WithElem<Tp, T>['normal']>;
): Reducer<T, WithElem<Tp, T>['normal']>;
}

@@ -405,3 +398,3 @@

*/
add: (value: T) => boolean;
add(value: T): boolean;
/**

@@ -416,3 +409,3 @@ * Adds the values in given `values` `StreamSource` to the builder.

*/
addAll: (values: StreamSource<T>) => boolean;
addAll(values: StreamSource<T>): boolean;
/**

@@ -462,3 +455,3 @@ * Remove the given `value` from the builder.

*/
build: () => WithElem<Tp, T>['normal'];
build(): WithElem<Tp, T>['normal'];
}

@@ -488,2 +481,4 @@

readonly _fixedElementType!: any;
get _types(): Tp {

@@ -490,0 +485,0 @@ return undefined as any;

@@ -35,7 +35,7 @@ import type { Streamable } from '@rimbu/stream';

export interface Types extends RSetBase.Types {
normal: RSet<this['_T']>;
nonEmpty: RSet.NonEmpty<this['_T']>;
context: RSet.Context<this['_T']>;
builder: RSet.Builder<this['_T']>;
readonly normal: RSet<this['_T']>;
readonly nonEmpty: RSet.NonEmpty<this['_T']>;
readonly context: RSet.Context<this['_T']>;
readonly builder: RSet.Builder<this['_T']>;
}
}

@@ -30,5 +30,5 @@ import type { Streamable } from '@rimbu/stream';

export interface Types extends VariantSetBase.Types {
normal: VariantSet<this['_T']>;
nonEmpty: VariantSet.NonEmpty<this['_T']>;
readonly normal: VariantSet<this['_T']>;
readonly nonEmpty: VariantSet.NonEmpty<this['_T']>;
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc