Skip to content

Commit

Permalink
feat: add typescript 4.5 rc compatibility and remove need to enable n…
Browse files Browse the repository at this point in the history
…oStrictGenericChecks

BREAKING CHANGE: Interfaces for methods like merge and flatten have been moved from instance to
class methods
  • Loading branch information
vitoke committed Nov 12, 2021
1 parent fdca138 commit 056dd8a
Show file tree
Hide file tree
Showing 78 changed files with 796 additions and 951 deletions.
1 change: 0 additions & 1 deletion config/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"downlevelIteration": true,
"noStrictGenericChecks": true,
"baseUrl": "./",
"isolatedModules": true,
"importsNotUsedAsValues": "error"
Expand Down
1 change: 0 additions & 1 deletion config/tsconfig.main.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"downlevelIteration": true,
"noStrictGenericChecks": true,
"baseUrl": "./",
"isolatedModules": true,
"importsNotUsedAsValues": "error",
Expand Down
1 change: 0 additions & 1 deletion config/tsconfig.module.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"downlevelIteration": true,
"noStrictGenericChecks": true,
"baseUrl": "./",
"isolatedModules": true,
"importsNotUsedAsValues": "error",
Expand Down
1 change: 0 additions & 1 deletion config/tsconfig.types.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"downlevelIteration": true,
"noStrictGenericChecks": true,
"baseUrl": "./",
"isolatedModules": true,
"importsNotUsedAsValues": "error",
Expand Down
4 changes: 2 additions & 2 deletions deno_dist/bimultimap/implementation/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import {
} from '../bimultimap-custom.ts';

export interface ContextTypesImpl extends BiMultiMapBase.Types {
context: BiMultiMapContext<this['_K'], this['_V'], string, this>;
context: BiMultiMapContext<this['_K'], this['_V'], string>;
}

export class BiMultiMapContext<
UK,
UV,
N extends string,
Tp extends ContextTypesImpl
Tp extends ContextTypesImpl = ContextTypesImpl
> implements BiMultiMapBase.Context<UK, UV, Tp>
{
constructor(
Expand Down
2 changes: 1 addition & 1 deletion deno_dist/collection-types/set/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export namespace RSetBase {
* result.toArray() // => [1, 2, 3, 20, 21, 22, 23, 24]
* @note uses an RSet builder under the hood. If the given `source` is a RSet in the same context, it will directly call `.toBuilder()`.
*/
reducer: <T>(
reducer: <T extends UT>(
source?: StreamSource<T>
) => Reducer<T, WithElem<Tp, T>['normal']>;
}
Expand Down
34 changes: 10 additions & 24 deletions deno_dist/hashed/map/immutable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ export class HashMapEmpty<K = any, V = any>
return this;
}

mergeAll<O, I extends readonly [unknown, ...unknown[]]>(
fillValue: O,
...sources: { [KT in keyof I]: StreamSource<readonly [K, I[KT]]> }
): any {
mergeAll<O>(fillValue: O, ...sources: any): any {
return this.context.mergeAll(
fillValue,
this,
Expand All @@ -123,7 +120,7 @@ export class HashMapEmpty<K = any, V = any>
value: V | O,
...values: { [KT in keyof I]: I[KT] | O }
) => R,
...sources: { [KT in keyof I]: StreamSource<readonly [K, I[KT]]> }
...sources: any
): any {
return this.context.mergeAllWith(
fillValue,
Expand All @@ -133,15 +130,13 @@ export class HashMapEmpty<K = any, V = any>
);
}

merge<I extends readonly [unknown, ...unknown[]]>(
...sources: { [KT in keyof I]: StreamSource<readonly [K, I[KT]]> }
): any {
merge(...sources: any): any {
return this.context.merge(this, ...(sources as any as 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]]> }
...sources: any
): any {
return this.context.mergeWith(
mergeFun as any,
Expand Down Expand Up @@ -286,25 +281,18 @@ export abstract class HashMapNonEmptyBase<K, V>
return this;
}

mergeAll<O, I extends readonly [unknown, ...unknown[]]>(
fillValue: O,
...sources: { [KT in keyof I]: StreamSource<readonly [K, I[KT]]> }
): any {
mergeAll<O>(fillValue: O, ...sources: any): any {
return this.context.mergeAll(
fillValue,
this,
...(sources as any as [any, ...any[]])
);
}

mergeAllWith<R, O, I extends readonly [unknown, ...unknown[]]>(
mergeAllWith<R, O>(
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]]> }
mergeFun: (key: K, value: V | O, ...values: any) => R,
...sources: any
): any {
return this.context.mergeAllWith(
fillValue,
Expand All @@ -314,15 +302,13 @@ export abstract class HashMapNonEmptyBase<K, V>
);
}

merge<I extends readonly [unknown, ...unknown[]]>(
...sources: { [KT in keyof I]: StreamSource<readonly [K, I[KT]]> }
): any {
merge(...sources: any): any {
return this.context.merge(this, ...(sources as any as 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]]> }
...sources: any
): any {
return this.context.mergeWith(
mergeFun as any,
Expand Down
10 changes: 9 additions & 1 deletion deno_dist/list/context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RimbuError } from '../base/mod.ts';
import type { ArrayNonEmpty } from '../common/mod.ts';
import { Reducer } from '../common/mod.ts';
import { StreamSource } from '../stream/mod.ts';
import { Stream, StreamSource } from '../stream/mod.ts';
import type { List } from './internal.ts';
import type {
Block,
Expand Down Expand Up @@ -135,6 +135,14 @@ export class ListContext implements List.Context {
);
};

flatten = (source: any): any => this.from(source).flatMap((s: any) => s);

unzip = (source: any, length: number): any => {
const streams = Stream.unzip(source, length) as any as Stream<any>[];

return Stream.from(streams).mapPure(this.from) as any;
};

leafBlock<T>(children: readonly T[]): LeafBlock<T> {
return new LeafBlock(this, children);
}
Expand Down
14 changes: 1 addition & 13 deletions deno_dist/list/implementation/empty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class Empty<T = any> extends CustomBase.EmptyBase implements List<T> {
return this;
}

concat(...sources: ArrayNonEmpty<StreamSource<T>>): any {
concat<T2>(...sources: ArrayNonEmpty<StreamSource<T2>>): any {
return this.context.from(...sources);
}

Expand Down Expand Up @@ -122,16 +122,4 @@ export class Empty<T = any> extends CustomBase.EmptyBase implements List<T> {
value: [],
};
}

extendType(): List<any> {
return this as any;
}

unzip(length: number): any {
return Stream.of(this).repeat(length).toArray();
}

flatten(): any {
return this;
}
}
51 changes: 24 additions & 27 deletions deno_dist/list/implementation/leaf/non-empty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
CollectFun,
IndexRange,
OptLazy,
SuperOf,
ToJSON,
TraverseState,
Update,
Expand Down Expand Up @@ -42,7 +41,9 @@ export abstract class ListNonEmptyBase<T>
abstract append(value: T): List.NonEmpty<T>;
abstract take(amount: number): List<T> | any;
abstract drop(amount: number): List<T>;
abstract concat(...sources: ArrayNonEmpty<StreamSource<T>>): List.NonEmpty<T>;
abstract concat<T2>(
...sources: ArrayNonEmpty<StreamSource<T2>>
): List.NonEmpty<T | T2>;
abstract updateAt(index: number, update: Update<T>): List.NonEmpty<T>;
abstract map<T2>(
mapFun: (value: T, index: number) => T2,
Expand Down Expand Up @@ -229,20 +230,6 @@ export abstract class ListNonEmptyBase<T>
value: this.toArray(),
};
}

extendType<T2>(): List.NonEmpty<SuperOf<T2, T>> {
return this as any;
}

unzip<L extends number>(length: L): any {
const streams = Stream.from(this).unzip(length) as any as Stream<any>[];

return Stream.from(streams).mapPure(this.context.from);
}

flatten(): any {
return this.flatMap((values: any) => values);
}
}

export class LeafBlock<T>
Expand Down Expand Up @@ -385,16 +372,20 @@ export class LeafBlock<T>
return this.copy(newChildren);
}

concat(...sources: ArrayNonEmpty<StreamSource<T>>): List.NonEmpty<T> {
const asList: List<T> = this.context.from(...sources);
concat<T2>(
...sources: ArrayNonEmpty<StreamSource<T2>>
): List.NonEmpty<T | T2> {
const asList: List<T | T2> = this.context.from(...sources);

if (asList.nonEmpty()) {
if (this.context.isLeafBlock(asList)) return this.concatBlock(asList);
if (this.context.isLeafTree(asList)) return this.concatTree(asList);
if (this.context.isLeafBlock(asList))
return (this as LeafBlock<T | T2>).concatBlock(asList);
if (this.context.isLeafTree(asList))
return (this as LeafBlock<T | T2>).concatTree(asList);
RimbuError.throwInvalidStateError();
}

return this;
return this as List.NonEmpty<T | T2>;
}

concatBlock(other: LeafBlock<T>): List.NonEmpty<T> {
Expand Down Expand Up @@ -768,16 +759,22 @@ export class LeafTree<T>
return this.copy(newLeft, undefined, newMiddle)._normalize();
}

concat(...sources: ArrayNonEmpty<StreamSource<T>>): List.NonEmpty<T> {
const asList: List<T> = this.context.from(...sources);
concat<T2>(
...sources: ArrayNonEmpty<StreamSource<T2>>
): List.NonEmpty<T | T2> {
const asList: List<T | T2> = this.context.from(...sources);

if (asList.nonEmpty()) {
if (this.context.isLeafBlock(asList)) return this.concatBlock(asList);
else if (this.context.isLeafTree(asList)) return this.concatTree(asList);
else RimbuError.throwInvalidStateError();
if (this.context.isLeafBlock(asList)) {
return (this as LeafTree<T | T2>).concatBlock(asList);
} else if (this.context.isLeafTree(asList)) {
return (this as LeafTree<T | T2>).concatTree(asList);
} else {
RimbuError.throwInvalidStateError();
}
}

return this;
return this as List.NonEmpty<T | T2>;
}

concatBlock(other: LeafBlock<T>): List.NonEmpty<T> {
Expand Down
4 changes: 2 additions & 2 deletions deno_dist/list/implementation/nonleaf/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { IndexRange, TraverseState, Update } from '../../../common/mod.ts';
import type { Stream } from '../../../stream/mod.ts';
import type { Block, ListContext } from '../../list-custom.ts';

export interface NonLeaf<T, C extends Block<T, C> = any> {
export interface NonLeaf<T, C extends Block<any, C> = any> {
readonly length: number;
readonly context: ListContext;
get(index: number): T;
Expand All @@ -12,7 +12,7 @@ export interface NonLeaf<T, C extends Block<T, C> = any> {
dropLast(): [NonLeaf<T, C> | null, C];
dropInternal(amount: number): [NonLeaf<T, C> | null, C, number];
takeInternal(amount: number): [NonLeaf<T, C> | null, C, number];
concat(other: NonLeaf<T, C>): NonLeaf<T, C>;
concat<T2>(other: NonLeaf<T2, C>): NonLeaf<T | T2, C>;
updateAt(index: number, update: Update<T>): NonLeaf<T, C>;
stream(reversed?: boolean): Stream.NonEmpty<T>;
streamRange(range: IndexRange, reversed?: boolean): Stream<T>;
Expand Down
7 changes: 4 additions & 3 deletions deno_dist/list/implementation/nonleaf/nonleaf-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,10 @@ export class NonLeafBlock<T, C extends Block<T, C>>
return [newSelf, lastChild];
}

concat(other: NonLeaf<T, C>): NonLeaf<T, C> {
if (other instanceof NonLeafBlock) return this.concatBlock(other);
if (this.context.isNonLeafTree(other)) return this.concatTree(other);
concat<T2>(other: NonLeaf<T2, C>): NonLeaf<T | T2, C> {
if (other instanceof NonLeafBlock) return (this as any).concatBlock(other);
if (this.context.isNonLeafTree(other))
return (this as any).concatTree(other);

RimbuError.throwInvalidStateError();
}
Expand Down
8 changes: 5 additions & 3 deletions deno_dist/list/implementation/nonleaf/nonleaf-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,11 @@ export class NonLeafTree<T, C extends Block<T, C>>
return newSelf.dropInternal(inUpLeft);
}

concat(other: NonLeaf<T, C>): NonLeaf<T, C> {
if (this.context.isNonLeafBlock<T>(other)) return this.concatBlock(other);
if (this.context.isNonLeafTree(other)) return this.concatTree(other);
concat<T2>(other: NonLeaf<T2, C>): NonLeaf<T | T2, C> {
if (this.context.isNonLeafBlock(other))
return (this as any).concatBlock(other);
if (this.context.isNonLeafTree(other))
return (this as any).concatTree(other);

RimbuError.throwInvalidStateError();
}
Expand Down

0 comments on commit 056dd8a

Please sign in to comment.