Skip to content

Commit

Permalink
feat: integrate release version of TypeScript 4.5, improve build times
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Some methods are extracted from Stream instances and made static, same for Maps and
Sets. This leads to better variance inference.
  • Loading branch information
vitoke committed Nov 18, 2021
1 parent 056dd8a commit d684828
Show file tree
Hide file tree
Showing 144 changed files with 2,982 additions and 3,810 deletions.
59 changes: 28 additions & 31 deletions deno_dist/bimap/interface/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,27 @@ export interface BiMap<K, V> extends FastIterable<readonly [K, V]> {
* // => [[1, 2]]
* @note if the key and/or value are already associated, the previous value will be 'replaced'
*/
set: (key: K, value: V) => BiMap.NonEmpty<K, V>;
set(key: K, value: V): BiMap.NonEmpty<K, V>;
/**
* Returns the collection with given `entry` added.
* @param entry - a tuple containing a key and value
* @example
* BiMap.of([1, 1], [2, 2]).addEntry([1, 2]).toArray()
* // => [[1, 2]]
*/
addEntry: (entry: readonly [K, V]) => BiMap.NonEmpty<K, V>;
addEntry(entry: readonly [K, V]): BiMap.NonEmpty<K, V>;
/**
* Returns the collection with the entries from the given `StreamSource` `entries` added.
* @param entries - a `StreamSource` containing tuples with a key and value
* @example
* BiMap.of([1, 1]).addEntries([[2, 2], [1, 3]]).toArray()
* // => [[1, 3], [2, 2]]
*/
addEntries: {
(entries: StreamSource.NonEmpty<readonly [K, V]>): BiMap.NonEmpty<K, V>;
(entries: StreamSource<readonly [K, V]>): BiMap<K, V>;
};
addEntries(
entries: StreamSource.NonEmpty<readonly [K, V]>
): BiMap.NonEmpty<K, V>;
addEntries(entries: StreamSource<readonly [K, V]>): BiMap<K, V>;

/**
* Returns the collection where the entry associated with given `key` is removed if it was part of the collection.
* @param key - the key of the entry to remove
Expand Down Expand Up @@ -302,7 +303,7 @@ export interface BiMap<K, V> extends FastIterable<readonly [K, V]> {
* @example
* const builder: BiMap.Builder<number, string> = BiMap.of([1, 'a'], [2, 'b']).toBuilder()
*/
toBuilder: () => BiMap.Builder<K, V>;
toBuilder(): BiMap.Builder<K, V>;
/**
* Returns an array containing all entries in this collection.
* @example
Expand Down Expand Up @@ -380,9 +381,7 @@ export namespace BiMap {
* BiMap.of([1, 1]).addEntries([[2, 2], [1, 3]]).toArray()
* // => [[1, 2]]
*/
addEntries: (
entries: StreamSource<readonly [K, V]>
) => BiMap.NonEmpty<K, V>;
addEntries(entries: StreamSource<readonly [K, V]>): BiMap.NonEmpty<K, V>;
/**
* Returns the collection where the value associated with given `key` is updated with the given `update` value or update function.
* @param key - the key of the entry to update
Expand Down Expand Up @@ -467,36 +466,34 @@ export namespace BiMap {
* BiMap.empty<number, string>() // => BiMap<number, string>
* BiMap.empty<string, boolean>() // => BiMap<string, boolean>
*/
empty: <K extends UK, V extends UV>() => BiMap<K, V>;
empty<K extends UK, V extends UV>(): BiMap<K, V>;
/**
* Returns an immutable `BiMap`, containing the given `entries`.
* @param entries - a non-empty array of key-value entries
* @example
* BiMap.of([1, 'a'], [2, 'b']) // => BiMap.NonEmpty<number, string>
*/
of: <K extends UK, V extends UV>(
of<K extends UK, V extends UV>(
...entries: ArrayNonEmpty<readonly [K, V]>
) => BiMap.NonEmpty<K, V>;
): BiMap.NonEmpty<K, V>;
/**
* Returns an immutable BiMap, containing the entries in the given `sources` `StreamSource` instances.
* @param sources - an array of `StreamSource` instances contaning key-value entries
* @example
* BiMap.from([[1, 'a'], [2, 'b']]) // => BiMap.NonEmpty<number, string>
*/
from: {
<K extends UK, V extends UV>(
...sources: ArrayNonEmpty<StreamSource<readonly [K, V]>>
): BiMap.NonEmpty<K, V>;
<K extends UK, V extends UV>(
...sources: ArrayNonEmpty<StreamSource.NonEmpty<readonly [K, V]>>
): BiMap<K, V>;
};
from<K extends UK, V extends UV>(
...sources: ArrayNonEmpty<StreamSource<readonly [K, V]>>
): BiMap.NonEmpty<K, V>;
from<K extends UK, V extends UV>(
...sources: ArrayNonEmpty<StreamSource.NonEmpty<readonly [K, V]>>
): BiMap<K, V>;
/**
* Returns an empty `BiMap` builder instance.
* @example
* BiMap.builder<number, string>() // => BiMap.Builder<number, string>
*/
builder: <K extends UK, V extends UV>() => BiMap.Builder<K, V>;
builder<K extends UK, V extends UV>(): BiMap.Builder<K, V>;
/**
* Returns a `Reducer` that adds received tuples to a BiMap and returns the BiMap as a result. When a `source` is given,
* the reducer will first create a BiMap from the source, and then add tuples to it.
Expand All @@ -507,16 +504,16 @@ export namespace BiMap {
* result.toArray() // => [[1, 'c'], [2, 'b'], [3, 'a']]
* @note uses a builder under the hood. If the given `source` is a BiMap in the same context, it will directly call `.toBuilder()`.
*/
reducer: <K extends UK, V extends UV>(
reducer<K extends UK, V extends UV>(
source?: StreamSource<readonly [K, V]>
) => Reducer<readonly [K, V], BiMap<K, V>>;
): Reducer<readonly [K, V], BiMap<K, V>>;
}

export interface Types extends CustomBase.KeyValue {
normal: BiMap<this['_K'], this['_V']>;
nonEmpty: BiMap.NonEmpty<this['_K'], this['_V']>;
limitKey: true;
limitValue: true;
readonly normal: BiMap<this['_K'], this['_V']>;
readonly nonEmpty: BiMap.NonEmpty<this['_K'], this['_V']>;
readonly limitKey: true;
readonly limitValue: true;
}

/**
Expand Down Expand Up @@ -593,7 +590,7 @@ export namespace BiMap {
* m.set(1, 'a') // => false
* m.set(1, 'b') // => true
*/
set: (key: K, value: V) => boolean;
set(key: K, value: V): boolean;
/**
* Adds the given `entry` to the builder, where the entry key is associated with the entry value.
* @param entry - the entry to add
Expand All @@ -603,7 +600,7 @@ export namespace BiMap {
* m.addEntry([1, 'a']) // => false
* m.addEntry([1, 'b']) // => true
*/
addEntry: (entry: readonly [K, V]) => boolean;
addEntry(entry: readonly [K, V]): boolean;
/**
* Adds given `entries` to the builder.
* @param entries - a `StreamSource` containing the entries to add
Expand All @@ -613,7 +610,7 @@ export namespace BiMap {
* m.addEntries([1, 'a'], [3, 'c']]) // => true
* m.addEntries([]) // => false
*/
addEntries: (entries: StreamSource<readonly [K, V]>) => boolean;
addEntries(entries: StreamSource<readonly [K, V]>): boolean;
/**
* Removes the entries related to given `key` from the builder.
* @param key - the key to remove
Expand Down
131 changes: 59 additions & 72 deletions deno_dist/bimultimap/interface/base/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,26 +134,20 @@ export interface BiMultiMapBase<
* HashBiMultiMap.of([1, 1], [2, 2]).add(1, 2).toArray()
* // => [[1, 1], [1, 2], [2, 2]]
*/
add: (key: K, value: V) => CB.WithKeyValue<Tp, K, V>['nonEmpty'];
add(key: K, value: V): CB.WithKeyValue<Tp, K, V>['nonEmpty'];
/**
* Returns the collection with the entries from the given `StreamSource` `entries` added.
* @param entries - a `StreamSource` containing tuples with a key and value
* @example
* HashBiMultiMap.of([1, 1]).addEntries([[2, 2], [1, 3]]).toArray()
* // => [[1, 1], [1, 3], [2, 2]]
*/
addEntries: {
(entries: StreamSource.NonEmpty<readonly [K, V]>): CB.WithKeyValue<
Tp,
K,
V
>['nonEmpty'];
(entries: StreamSource<readonly [K, V]>): CB.WithKeyValue<
Tp,
K,
V
>['normal'];
};
addEntries(
entries: StreamSource.NonEmpty<readonly [K, V]>
): CB.WithKeyValue<Tp, K, V>['nonEmpty'];
addEntries(
entries: StreamSource<readonly [K, V]>
): CB.WithKeyValue<Tp, K, V>['normal'];
/**
* Returns the collection with the values from the given `values` StreamSource associated
* with the given `key`.
Expand All @@ -163,14 +157,14 @@ export interface BiMultiMapBase<
* HashBiMultiMap.of([1, 1]).setValues(1, [2, 3]).toArray()
* // => [[1, 1], [1, 2], [1, 3]]
*/
setValues: {
(key: K, values: StreamSource.NonEmpty<V>): CB.WithKeyValue<
Tp,
K,
V
>['nonEmpty'];
(key: K, values: StreamSource<V>): CB.WithKeyValue<Tp, K, V>['normal'];
};
setValues(
key: K,
values: StreamSource.NonEmpty<V>
): CB.WithKeyValue<Tp, K, V>['nonEmpty'];
setValues(
key: K,
values: StreamSource<V>
): CB.WithKeyValue<Tp, K, V>['normal'];
/**
* Returns the collection with the keys from the given `keys` StreamSource associated
* with the given `value`.
Expand All @@ -180,14 +174,11 @@ export interface BiMultiMapBase<
* HashBiMultiMap.of([1, 1]).setKeys(1, [2, 3]).toArray()
* // => [[1, 1], [2, 1], [3, 1]]
*/
setKeys: {
(value: V, keys: StreamSource.NonEmpty<K>): CB.WithKeyValue<
Tp,
K,
V
>['nonEmpty'];
(value: V, keys: StreamSource<K>): CB.WithKeyValue<Tp, K, V>['normal'];
};
setKeys(
value: V,
keys: StreamSource.NonEmpty<K>
): CB.WithKeyValue<Tp, K, V>['nonEmpty'];
setKeys(value: V, keys: StreamSource<K>): CB.WithKeyValue<Tp, K, V>['normal'];
/**
* Returns a collection containing the values associated with the given `key`.
* @param key - the key of which to find the values
Expand Down Expand Up @@ -344,7 +335,7 @@ export interface BiMultiMapBase<
* @example
* const builder: HashBiMultiMap.Builder<number, string> = HashBiMultiMap.of([1, 'a'], [2, 'b']).toBuilder()
*/
toBuilder: () => CB.WithKeyValue<Tp, K, V>['builder'];
toBuilder(): CB.WithKeyValue<Tp, K, V>['builder'];
}

export namespace BiMultiMapBase {
Expand Down Expand Up @@ -419,9 +410,9 @@ export namespace BiMultiMapBase {
* HashBiMultiMap.of([1, 1]).addEntries([[2, 2], [1, 3]]).toArray()
* // => [[1, 1], [1, 3], [2, 2]]
*/
addEntries: (
addEntries(
entries: StreamSource<readonly [K, V]>
) => CB.WithKeyValue<Tp, K, V>['nonEmpty'];
): CB.WithKeyValue<Tp, K, V>['nonEmpty'];
}

export interface Context<
Expand Down Expand Up @@ -454,44 +445,34 @@ export namespace BiMultiMapBase {
* HashBiMultiMap.empty<number, string>() // => HashBiMultiMap<number, string>
* HashBiMultiMap.empty<string, boolean>() // => HashBiMultiMap<string, boolean>
*/
empty: <K extends UK, V extends UV>() => CB.WithKeyValue<
Tp,
K,
V
>['normal'];
empty<K extends UK, V extends UV>(): CB.WithKeyValue<Tp, K, V>['normal'];
/**
* Returns an immutable BiMultiMap, containing the given `entries`.
* @param entries - a non-empty array of key-value entries
* @example
* HashBiMultiMap.of([1, 'a'], [2, 'b']) // => HashBiMultiMap.NonEmpty<number, string>
*/
of: <K extends UK, V extends UV>(
of<K extends UK, V extends UV>(
...entries: ArrayNonEmpty<readonly [K, V]>
) => CB.WithKeyValue<Tp, K, V>['nonEmpty'];
): CB.WithKeyValue<Tp, K, V>['nonEmpty'];
/**
* Returns an immutable BiMultiMap, containing the entries in the given `sources` `StreamSource` instances.
* @param sources - an array of `StreamSource` instances contaning key-value entries
* @example
* HashBiMultiMap.from([[1, 'a'], [2, 'b']]) // => HashBiMultiMap.NonEmpty<number, string>
*/
from: {
<K extends UK, V extends UV>(
...sources: ArrayNonEmpty<StreamSource.NonEmpty<readonly [K, V]>>
): CB.WithKeyValue<Tp, K, V>['nonEmpty'];
<K extends UK, V extends UV>(
...sources: ArrayNonEmpty<StreamSource<readonly [K, V]>>
): CB.WithKeyValue<Tp, K, V>['normal'];
};
from<K extends UK, V extends UV>(
...sources: ArrayNonEmpty<StreamSource.NonEmpty<readonly [K, V]>>
): CB.WithKeyValue<Tp, K, V>['nonEmpty'];
from<K extends UK, V extends UV>(
...sources: ArrayNonEmpty<StreamSource<readonly [K, V]>>
): CB.WithKeyValue<Tp, K, V>['normal'];
/**
* Returns an empty `BiMultiMap` builder instance.
* @example
* HashBiMultiMap.builder<number, string>() // => HashBiMultiMap.Builder<number, string>
*/
builder: <K extends UK, V extends UV>() => CB.WithKeyValue<
Tp,
K,
V
>['builder'];
builder<K extends UK, V extends UV>(): CB.WithKeyValue<Tp, K, V>['builder'];
/**
* Returns a `Reducer` that adds received tuples to a BiMultiMap and returns the BiMultiMap as a result. When a `source` is given,
* the reducer will first create a BiMultiMap from the source, and then add tuples to it.
Expand All @@ -502,9 +483,9 @@ export namespace BiMultiMapBase {
* result.toArray() // => [[1, 'a'], [1, 'c'], [2, 'b'], [3, 'a']]
* @note uses a builder under the hood. If the given `source` is a BiMultiMap in the same context, it will directly call `.toBuilder()`.
*/
reducer: <K extends UK, V extends UV>(
reducer<K extends UK, V extends UV>(
source?: StreamSource<readonly [K, V]>
) => Reducer<[K, V], CB.WithKeyValue<Tp, K, V>['normal']>;
): Reducer<[K, V], CB.WithKeyValue<Tp, K, V>['normal']>;
}

export interface Builder<
Expand Down Expand Up @@ -591,7 +572,7 @@ export namespace BiMultiMapBase {
* const m = HashBiMultiMap.of([1, 'a'], [2, 'b']).toBuilder()
* m.setValues(1, ['b', 'c']).getValues(1).toArray() // => ['b', 'c']
*/
setValues: (key: K, values: StreamSource<V>) => boolean;
setValues(key: K, values: StreamSource<V>): boolean;
/**
* Sets the keys associated to given `value` to the keys in the given `keys` StreamSource.
* @param value - the value to which to associate the keys
Expand All @@ -600,7 +581,7 @@ export namespace BiMultiMapBase {
* const m = HashBiMultiMap.of([1, 'a'], [2, 'b']).toBuilder()
* m.setKeys('a', [3, 4]).getKeys('a').toArray() // => [3, 4]
*/
setKeys: (value: V, keys: StreamSource<K>) => boolean;
setKeys(value: V, keys: StreamSource<K>): boolean;
/**
* Associates given `key` with given `value` in the builder.
* @param key - the entry key
Expand All @@ -611,7 +592,7 @@ export namespace BiMultiMapBase {
* m.set(1, 'a') // => false
* m.set(1, 'b') // => true
*/
add: (key: K, value: V) => boolean;
add(key: K, value: V): boolean;
/**
* Adds given `entries` to the builder.
* @param entries - a `StreamSource` containing the entries to add
Expand All @@ -621,7 +602,7 @@ export namespace BiMultiMapBase {
* m.addEntries([1, 'a'], [3, 'c']]) // => true
* m.addEntries([]) // => false
*/
addEntries: (entries: StreamSource<readonly [K, V]>) => boolean;
addEntries(entries: StreamSource<readonly [K, V]>): boolean;
/**
* Removes the entries related to given `key` from the builder.
* @param key - the key to remove
Expand Down Expand Up @@ -718,19 +699,25 @@ export namespace BiMultiMapBase {
}

export interface Types extends CB.KeyValue {
limitKey: true;
limitValue: true;
context: BiMultiMapBase.Context<this['_K'], this['_V']>;
normal: BiMultiMapBase<this['_K'], this['_V']>;
nonEmpty: BiMultiMapBase.NonEmpty<this['_K'], this['_V']>;
builder: BiMultiMapBase.Builder<this['_K'], this['_V']>;
keyValueMultiMapContext: MultiMap.Context<this['_K'], this['_V']>;
valueKeyMultiMapContext: MultiMap.Context<this['_V'], this['_K']>;
keyValueMultiMap: MultiMap<this['_K'], this['_V']>;
valueKeyMultiMap: MultiMap<this['_V'], this['_K']>;
keyValueMultiMapNonEmpty: MultiMap.NonEmpty<this['_K'], this['_V']>;
valueKeyMultiMapNonEmpty: MultiMap.NonEmpty<this['_V'], this['_K']>;
keyMultiMapValues: RSet<this['_V']>;
valueMultiMapValues: RSet<this['_K']>;
readonly limitKey: true;
readonly limitValue: true;
readonly context: BiMultiMapBase.Context<this['_K'], this['_V']>;
readonly normal: BiMultiMapBase<this['_K'], this['_V']>;
readonly nonEmpty: BiMultiMapBase.NonEmpty<this['_K'], this['_V']>;
readonly builder: BiMultiMapBase.Builder<this['_K'], this['_V']>;
readonly keyValueMultiMapContext: MultiMap.Context<this['_K'], this['_V']>;
readonly valueKeyMultiMapContext: MultiMap.Context<this['_V'], this['_K']>;
readonly keyValueMultiMap: MultiMap<this['_K'], this['_V']>;
readonly valueKeyMultiMap: MultiMap<this['_V'], this['_K']>;
readonly keyValueMultiMapNonEmpty: MultiMap.NonEmpty<
this['_K'],
this['_V']
>;
readonly valueKeyMultiMapNonEmpty: MultiMap.NonEmpty<
this['_V'],
this['_K']
>;
readonly keyMultiMapValues: RSet<this['_V']>;
readonly valueMultiMapValues: RSet<this['_K']>;
}
}

0 comments on commit d684828

Please sign in to comment.