@rimbu/list
Advanced tools
Comparing version 0.7.5 to 0.8.0
@@ -88,2 +88,7 @@ "use strict"; | ||
}; | ||
this.flatten = function (source) { return _this.from(source).flatMap(function (s) { return s; }); }; | ||
this.unzip = function (source, length) { | ||
var streams = stream_1.Stream.unzip(source, length); | ||
return stream_1.Stream.from(streams).mapPure(_this.from); | ||
}; | ||
if (blockSizeBits < 2) { | ||
@@ -90,0 +95,0 @@ base_1.RimbuError.throwInvalidUsageError('List: blockSizeBits should be at least 2'); |
@@ -108,11 +108,2 @@ "use strict"; | ||
}; | ||
Empty.prototype.extendType = function () { | ||
return this; | ||
}; | ||
Empty.prototype.unzip = function (length) { | ||
return stream_1.Stream.of(this).repeat(length).toArray(); | ||
}; | ||
Empty.prototype.flatten = function () { | ||
return this; | ||
}; | ||
return Empty; | ||
@@ -119,0 +110,0 @@ }(collection_types_1.CustomBase.EmptyBase)); |
@@ -155,12 +155,2 @@ "use strict"; | ||
}; | ||
ListNonEmptyBase.prototype.extendType = function () { | ||
return this; | ||
}; | ||
ListNonEmptyBase.prototype.unzip = function (length) { | ||
var streams = stream_1.Stream.from(this).unzip(length); | ||
return stream_1.Stream.from(streams).mapPure(this.context.from); | ||
}; | ||
ListNonEmptyBase.prototype.flatten = function () { | ||
return this.flatMap(function (values) { return values; }); | ||
}; | ||
return ListNonEmptyBase; | ||
@@ -399,3 +389,3 @@ }(collection_types_1.CustomBase.NonEmptyBase)); | ||
LeafBlock.prototype.structure = function () { | ||
return "<Leaf " + this.length + ">"; | ||
return "<Leaf ".concat(this.length, ">"); | ||
}; | ||
@@ -510,3 +500,3 @@ return LeafBlock; | ||
ReversedLeafBlock.prototype.structure = function () { | ||
return "<RLeaf " + this.length + ">"; | ||
return "<RLeaf ".concat(this.length, ">"); | ||
}; | ||
@@ -628,8 +618,11 @@ return ReversedLeafBlock; | ||
if (asList.nonEmpty()) { | ||
if (this.context.isLeafBlock(asList)) | ||
if (this.context.isLeafBlock(asList)) { | ||
return this.concatBlock(asList); | ||
else if (this.context.isLeafTree(asList)) | ||
} | ||
else if (this.context.isLeafTree(asList)) { | ||
return this.concatTree(asList); | ||
else | ||
} | ||
else { | ||
base_1.RimbuError.throwInvalidStateError(); | ||
} | ||
} | ||
@@ -778,3 +771,3 @@ return this; | ||
LeafTree.prototype.structure = function () { | ||
return "<LeafTree len:" + this.length + "\n l:" + this.left.structure() + "\n m: " + (this.middle && this.middle.structure()) + "\n r:" + this.right.structure() + "\n>"; | ||
return "<LeafTree len:".concat(this.length, "\n l:").concat(this.left.structure(), "\n m: ").concat(this.middle && this.middle.structure(), "\n r:").concat(this.right.structure(), "\n>"); | ||
}; | ||
@@ -781,0 +774,0 @@ return LeafTree; |
@@ -354,3 +354,3 @@ "use strict"; | ||
var space = ' '.padEnd(this.level * 2); | ||
return "\n" + space + "<NLBlock len:" + this.length + " c:" + this.nrChildren + " " + this.children.map(function (c) { return c.structure(); }).join(' ') + ">"; | ||
return "\n".concat(space, "<NLBlock len:").concat(this.length, " c:").concat(this.nrChildren, " ").concat(this.children.map(function (c) { return c.structure(); }).join(' '), ">"); | ||
}; | ||
@@ -357,0 +357,0 @@ return NonLeafBlock; |
@@ -243,3 +243,3 @@ "use strict"; | ||
var space = ' '.padEnd(this.level * 2); | ||
return "\n" + space + "<NLTree len:" + this.length + "\n l:" + this.left.structure() + "\n m:" + (this.middle && this.middle.structure()) + "\n r:" + this.right.structure() + "\n>"; | ||
return "\n".concat(space, "<NLTree len:").concat(this.length, "\n l:").concat(this.left.structure(), "\n m:").concat(this.middle && this.middle.structure(), "\n r:").concat(this.right.structure(), "\n>"); | ||
}; | ||
@@ -246,0 +246,0 @@ return NonLeafTree; |
import { RimbuError } from '@rimbu/base'; | ||
import { Reducer } from '@rimbu/common'; | ||
import { StreamSource } from '@rimbu/stream'; | ||
import { Stream, StreamSource } from '@rimbu/stream'; | ||
import { Empty, GenBuilder, LeafBlock, LeafBlockBuilder, LeafTree, LeafTreeBuilder, ListNonEmptyBase, NonLeafBlock, NonLeafBlockBuilder, NonLeafTree, NonLeafTreeBuilder, ReversedLeafBlock, } from './list-custom'; | ||
@@ -69,2 +69,7 @@ export class ListContext { | ||
}; | ||
this.flatten = (source) => this.from(source).flatMap((s) => s); | ||
this.unzip = (source, length) => { | ||
const streams = Stream.unzip(source, length); | ||
return Stream.from(streams).mapPure(this.from); | ||
}; | ||
if (blockSizeBits < 2) { | ||
@@ -71,0 +76,0 @@ RimbuError.throwInvalidUsageError('List: blockSizeBits should be at least 2'); |
@@ -97,12 +97,3 @@ import { CustomBase } from '@rimbu/collection-types'; | ||
} | ||
extendType() { | ||
return this; | ||
} | ||
unzip(length) { | ||
return Stream.of(this).repeat(length).toArray(); | ||
} | ||
flatten() { | ||
return this; | ||
} | ||
} | ||
//# sourceMappingURL=empty.js.map |
@@ -137,12 +137,2 @@ import { Arr, RimbuError } from '@rimbu/base'; | ||
} | ||
extendType() { | ||
return this; | ||
} | ||
unzip(length) { | ||
const streams = Stream.from(this).unzip(length); | ||
return Stream.from(streams).mapPure(this.context.from); | ||
} | ||
flatten() { | ||
return this.flatMap((values) => values); | ||
} | ||
} | ||
@@ -539,8 +529,11 @@ export class LeafBlock extends ListNonEmptyBase { | ||
if (asList.nonEmpty()) { | ||
if (this.context.isLeafBlock(asList)) | ||
if (this.context.isLeafBlock(asList)) { | ||
return this.concatBlock(asList); | ||
else if (this.context.isLeafTree(asList)) | ||
} | ||
else if (this.context.isLeafTree(asList)) { | ||
return this.concatTree(asList); | ||
else | ||
} | ||
else { | ||
RimbuError.throwInvalidStateError(); | ||
} | ||
} | ||
@@ -547,0 +540,0 @@ return this; |
@@ -21,2 +21,4 @@ import { Reducer } from '@rimbu/common'; | ||
reducer: <T>(source?: StreamSource<T> | undefined) => Reducer<T, List<T>>; | ||
flatten: (source: any) => any; | ||
unzip: (source: any, length: number) => any; | ||
leafBlock<T>(children: readonly T[]): LeafBlock<T>; | ||
@@ -23,0 +25,0 @@ reversedLeaf<T>(children: readonly T[]): ReversedLeafBlock<T>; |
@@ -23,3 +23,3 @@ import { CustomBase } from '@rimbu/collection-types'; | ||
remove(): this; | ||
concat(...sources: ArrayNonEmpty<StreamSource<T>>): any; | ||
concat<T2>(...sources: ArrayNonEmpty<StreamSource<T2>>): any; | ||
repeat(): this; | ||
@@ -39,5 +39,2 @@ rotate(): this; | ||
toJSON(): ToJSON<any[], this['context']['typeTag']>; | ||
extendType(): List<any>; | ||
unzip(length: number): any; | ||
flatten(): any; | ||
} |
import { CustomBase } from '@rimbu/collection-types'; | ||
import { ArrayNonEmpty, CollectFun, IndexRange, OptLazy, SuperOf, ToJSON, TraverseState, Update } from '@rimbu/common'; | ||
import { ArrayNonEmpty, CollectFun, IndexRange, OptLazy, ToJSON, TraverseState, Update } from '@rimbu/common'; | ||
import { FastIterator, Stream, StreamSource } from '@rimbu/stream'; | ||
@@ -17,3 +17,3 @@ import type { List } from '../../internal'; | ||
abstract drop(amount: number): List<T>; | ||
abstract concat(...sources: ArrayNonEmpty<StreamSource<T>>): List.NonEmpty<T>; | ||
abstract concat<T2 = T>(...sources: ArrayNonEmpty<StreamSource<T2>>): List.NonEmpty<T | T2>; | ||
abstract updateAt(index: number, update: Update<T>): List.NonEmpty<T>; | ||
@@ -48,5 +48,2 @@ abstract map<T2>(mapFun: (value: T, index: number) => T2, reversed?: boolean): List.NonEmpty<T2>; | ||
toJSON(): ToJSON<T[], this['context']['typeTag']>; | ||
extendType<T2>(): List.NonEmpty<SuperOf<T2, T>>; | ||
unzip<L extends number>(length: L): any; | ||
flatten(): any; | ||
} | ||
@@ -77,3 +74,3 @@ export declare class LeafBlock<T> extends ListNonEmptyBase<T> implements Block<T, LeafBlock<T>, T> { | ||
concatChildren(other: LeafBlock<T>): LeafBlock<T>; | ||
concat(...sources: ArrayNonEmpty<StreamSource<T>>): List.NonEmpty<T>; | ||
concat<T2>(...sources: ArrayNonEmpty<StreamSource<T2>>): List.NonEmpty<T | T2>; | ||
concatBlock(other: LeafBlock<T>): List.NonEmpty<T>; | ||
@@ -127,3 +124,3 @@ concatTree(other: LeafTree<T>): LeafTree<T>; | ||
drop(amount: number): List<T>; | ||
concat(...sources: ArrayNonEmpty<StreamSource<T>>): List.NonEmpty<T>; | ||
concat<T2>(...sources: ArrayNonEmpty<StreamSource<T2>>): List.NonEmpty<T | T2>; | ||
concatBlock(other: LeafBlock<T>): List.NonEmpty<T>; | ||
@@ -130,0 +127,0 @@ concatTree(other: LeafTree<T>): LeafTree<T>; |
import type { IndexRange, TraverseState, Update } from '@rimbu/common'; | ||
import type { Stream } from '@rimbu/stream'; | ||
import type { Block, ListContext } from '../../list-custom'; | ||
export interface NonLeaf<T, C extends Block<T, C> = any> { | ||
export interface NonLeaf<T, C extends Block<any, C> = any> { | ||
readonly length: number; | ||
@@ -14,3 +14,3 @@ readonly context: ListContext; | ||
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>; | ||
@@ -17,0 +17,0 @@ stream(reversed?: boolean): Stream.NonEmpty<T>; |
@@ -26,3 +26,3 @@ import { IndexRange, TraverseState, Update } from '@rimbu/common'; | ||
dropLast(): [NonLeafBlock<T, C> | null, C]; | ||
concat(other: NonLeaf<T, C>): NonLeaf<T, C>; | ||
concat<T2>(other: NonLeaf<T2, C>): NonLeaf<T | T2, C>; | ||
concatBlock(other: NonLeafBlock<T, C>): NonLeaf<T, C>; | ||
@@ -29,0 +29,0 @@ concatTree(other: NonLeafTree<T, C>): NonLeaf<T, C>; |
@@ -26,3 +26,3 @@ import type { IndexRange, TraverseState, Update } from '@rimbu/common'; | ||
dropInternal(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>; | ||
concatBlock(other: NonLeafBlock<T, C>): NonLeaf<T, C>; | ||
@@ -29,0 +29,0 @@ concatTree(other: NonLeafTree<T, C>): NonLeaf<T, C>; |
import type { CustomBase } from '@rimbu/collection-types'; | ||
import type { ArrayNonEmpty, CollectFun, IndexRange, OmitStrong, OptLazy, Reducer, StringNonEmpty, SuperOf, ToJSON, TraverseState, Update } from '@rimbu/common'; | ||
import type { ArrayNonEmpty, CollectFun, IndexRange, OmitStrong, OptLazy, Reducer, StringNonEmpty, ToJSON, TraverseState, Update } from '@rimbu/common'; | ||
import type { FastIterable, Stream, Streamable, StreamSource } from '@rimbu/stream'; | ||
@@ -229,4 +229,4 @@ /** | ||
*/ | ||
concat(...sources: ArrayNonEmpty<StreamSource.NonEmpty<T>>): List.NonEmpty<T>; | ||
concat(...sources: ArrayNonEmpty<StreamSource<T>>): List<T>; | ||
concat<T2 = T>(...sources: ArrayNonEmpty<StreamSource.NonEmpty<T2>>): List.NonEmpty<T | T2>; | ||
concat<T2 = T>(...sources: ArrayNonEmpty<StreamSource<T2>>): List<T | T2>; | ||
/** | ||
@@ -392,32 +392,2 @@ * Returns a List that contains this List the given `amount` of times. | ||
toJSON(): ToJSON<T[], this['context']['typeTag']>; | ||
/** | ||
* Returns the same `List` with a wider value type T2, if T2 | ||
* is a super type of T. | ||
* @typeparam T2 - a super type of T | ||
* @example | ||
* const m = List.of(1, 2, 3) | ||
* m.extendType<number | string>() | ||
* // type: List.NonEmpty<number | string> | ||
*/ | ||
extendType<T2>(): List<SuperOf<T2, T>>; | ||
/** | ||
* Returns an array of Lists, where each list contains the values of the corresponding index of tuple T. | ||
* @param length - the length of the tuples in type T | ||
* @example | ||
* const m = List.of([1, 'a'], [2, 'b']) | ||
* m.unzip(2) // => [List.NonEmpty<number>, List.NonEmpty<string>] | ||
*/ | ||
unzip<L extends number, T2 extends T = T>(length: L): T2 extends readonly [unknown, ...unknown[]] & { | ||
length: L; | ||
} ? { | ||
[K in keyof T2]: List<T2[K]>; | ||
} : never; | ||
/** | ||
* Returns, if T is a valid `StreamSource`, the result of concatenating all | ||
* streamable elements of this List. | ||
* @example | ||
* const m = List.of([1, 2], [3, 4, 5]) | ||
* m.flatten().toArray() // => [1, 2, 3, 4, 5] | ||
*/ | ||
flatten<T2 = T>(): T2 extends StreamSource.NonEmpty<infer S> ? List<S> : T2 extends StreamSource<infer S> ? List<S> : never; | ||
} | ||
@@ -496,3 +466,3 @@ export declare namespace List { | ||
*/ | ||
concat(...sources: ArrayNonEmpty<StreamSource<T>>): List.NonEmpty<T>; | ||
concat<T2 = T>(...sources: ArrayNonEmpty<StreamSource<T2>>): List.NonEmpty<T | T2>; | ||
/** | ||
@@ -631,25 +601,2 @@ * Returns, for a List of `StreamSource` instances of type T, a List of type T containing the concatenation | ||
toArray(range?: IndexRange, reversed?: boolean): T[]; | ||
/** | ||
* Returns the same `List` with a wider value type T2, if T2 | ||
* is a super type of T. | ||
* @typeparam T2 - a super type of T | ||
* @example | ||
* const m = List.of(1, 2, 3) | ||
* m.extendType<number | string>() | ||
* // type: List.NonEmpty<number | string> | ||
*/ | ||
extendType<T2>(): List.NonEmpty<SuperOf<T2, T>>; | ||
/** | ||
* Returns an array of Lists, where each list contains the values of the corresponding index of tuple T. | ||
* @param length - the length of the tuples in type T | ||
* @example | ||
* const m = List.of([1, 'a'], [2, 'b']) | ||
* m.unzip(2) // => [List.NonEmpty<number>, List.NonEmpty<string>] | ||
*/ | ||
unzip<L extends number, T2 extends T = T>(length: L): T2 extends readonly [unknown, ...unknown[]] & { | ||
length: L; | ||
} ? { | ||
[K in keyof T2]: List.NonEmpty<T2[K]>; | ||
} : never; | ||
flatten<T2 extends T = T>(): T2 extends StreamSource.NonEmpty<infer S> ? List.NonEmpty<S> : T2 extends StreamSource<infer S> ? List<S> : never; | ||
} | ||
@@ -865,2 +812,32 @@ interface Builder<T> { | ||
/** | ||
* Returns, if T is a valid `StreamSource`, the result of concatenating all | ||
* streamable elements of the given sources. | ||
* @example | ||
* const m = List.of([1, 2], [3, 4, 5]) | ||
* List.flatten(m).toArray() // => [1, 2, 3, 4, 5] | ||
*/ | ||
flatten: { | ||
<T extends StreamSource.NonEmpty<unknown>>(source: StreamSource.NonEmpty<T>): T extends StreamSource.NonEmpty<infer S> ? List.NonEmpty<S> : never; | ||
<T extends StreamSource<unknown>>(source: StreamSource<T>): T extends StreamSource<infer S> ? List<S> : never; | ||
}; | ||
/** | ||
* Returns an array of Lists, where each list contains the values of the corresponding index of tuple T. | ||
* @param length - the length of the tuples in type T | ||
* @example | ||
* const m = List.of([1, 'a'], [2, 'b']) | ||
* List.unzip(m) // => [List.NonEmpty<number>, List.NonEmpty<string>] | ||
*/ | ||
unzip: { | ||
<T extends readonly unknown[] & { | ||
length: L; | ||
}, L extends number>(source: StreamSource.NonEmpty<T>, length: L): { | ||
[K in keyof T]: List.NonEmpty<T[K]>; | ||
}; | ||
<T extends readonly unknown[] & { | ||
length: L; | ||
}, L extends number>(source: StreamSource<T>, length: L): { | ||
[K in keyof T]: List<T[K]>; | ||
}; | ||
}; | ||
/** | ||
* Returns an empty List Builder based on this context. | ||
@@ -867,0 +844,0 @@ * @example |
{ | ||
"name": "@rimbu/list", | ||
"version": "0.7.5", | ||
"version": "0.8.0", | ||
"description": "An efficient immutable ordered sequence of elements akin to a Vector", | ||
@@ -62,6 +62,6 @@ "keywords": [ | ||
"dependencies": { | ||
"@rimbu/base": "^0.6.7", | ||
"@rimbu/collection-types": "^0.7.5", | ||
"@rimbu/common": "^0.7.5", | ||
"@rimbu/stream": "^0.7.5", | ||
"@rimbu/base": "^0.7.0", | ||
"@rimbu/collection-types": "^0.8.0", | ||
"@rimbu/common": "^0.8.0", | ||
"@rimbu/stream": "^0.8.0", | ||
"tslib": "^2.3.1" | ||
@@ -75,3 +75,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 | ||
} | ||
} | ||
``` | ||
## Usage | ||
@@ -68,0 +55,0 @@ |
import { RimbuError } from '@rimbu/base'; | ||
import type { ArrayNonEmpty } from '@rimbu/common'; | ||
import { Reducer } from '@rimbu/common'; | ||
import { StreamSource } from '@rimbu/stream'; | ||
import { Stream, StreamSource } from '@rimbu/stream'; | ||
import type { List } from './internal'; | ||
@@ -138,2 +138,10 @@ import type { | ||
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> { | ||
@@ -140,0 +148,0 @@ return new LeafBlock(this, children); |
@@ -62,3 +62,3 @@ import { CustomBase } from '@rimbu/collection-types'; | ||
concat(...sources: ArrayNonEmpty<StreamSource<T>>): any { | ||
concat<T2>(...sources: ArrayNonEmpty<StreamSource<T2>>): any { | ||
return this.context.from(...sources); | ||
@@ -126,14 +126,2 @@ } | ||
} | ||
extendType(): List<any> { | ||
return this as any; | ||
} | ||
unzip(length: number): any { | ||
return Stream.of(this).repeat(length).toArray(); | ||
} | ||
flatten(): any { | ||
return this; | ||
} | ||
} |
@@ -8,3 +8,2 @@ import { Arr, RimbuError } from '@rimbu/base'; | ||
OptLazy, | ||
SuperOf, | ||
ToJSON, | ||
@@ -46,3 +45,5 @@ TraverseState, | ||
abstract drop(amount: number): List<T>; | ||
abstract concat(...sources: ArrayNonEmpty<StreamSource<T>>): List.NonEmpty<T>; | ||
abstract concat<T2 = T>( | ||
...sources: ArrayNonEmpty<StreamSource<T2>> | ||
): List.NonEmpty<T | T2>; | ||
abstract updateAt(index: number, update: Update<T>): List.NonEmpty<T>; | ||
@@ -234,16 +235,2 @@ abstract map<T2>( | ||
} | ||
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); | ||
} | ||
} | ||
@@ -391,12 +378,16 @@ | ||
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>; | ||
} | ||
@@ -775,12 +766,18 @@ | ||
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>; | ||
} | ||
@@ -787,0 +784,0 @@ |
@@ -5,3 +5,3 @@ import type { IndexRange, TraverseState, Update } from '@rimbu/common'; | ||
export interface NonLeaf<T, C extends Block<T, C> = any> { | ||
export interface NonLeaf<T, C extends Block<any, C> = any> { | ||
readonly length: number; | ||
@@ -16,3 +16,3 @@ readonly context: ListContext; | ||
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>; | ||
@@ -19,0 +19,0 @@ stream(reversed?: boolean): Stream.NonEmpty<T>; |
@@ -175,5 +175,6 @@ import { Arr, RimbuError } from '@rimbu/base'; | ||
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); | ||
@@ -180,0 +181,0 @@ RimbuError.throwInvalidStateError(); |
@@ -216,5 +216,7 @@ import { RimbuError } from '@rimbu/base'; | ||
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); | ||
@@ -221,0 +223,0 @@ RimbuError.throwInvalidStateError(); |
@@ -10,3 +10,2 @@ import type { CustomBase } from '@rimbu/collection-types'; | ||
StringNonEmpty, | ||
SuperOf, | ||
ToJSON, | ||
@@ -249,4 +248,6 @@ TraverseState, | ||
*/ | ||
concat(...sources: ArrayNonEmpty<StreamSource.NonEmpty<T>>): List.NonEmpty<T>; | ||
concat(...sources: ArrayNonEmpty<StreamSource<T>>): List<T>; | ||
concat<T2 = T>( | ||
...sources: ArrayNonEmpty<StreamSource.NonEmpty<T2>> | ||
): List.NonEmpty<T | T2>; | ||
concat<T2 = T>(...sources: ArrayNonEmpty<StreamSource<T2>>): List<T | T2>; | ||
/** | ||
@@ -430,14 +431,3 @@ * Returns a List that contains this List the given `amount` of times. | ||
toJSON(): ToJSON<T[], this['context']['typeTag']>; | ||
/** | ||
* Returns the same `List` with a wider value type T2, if T2 | ||
* is a super type of T. | ||
* @typeparam T2 - a super type of T | ||
* @example | ||
* const m = List.of(1, 2, 3) | ||
* m.extendType<number | string>() | ||
* // type: List.NonEmpty<number | string> | ||
*/ | ||
extendType<T2>(): List<SuperOf<T2, T>>; | ||
/** | ||
* Returns an array of Lists, where each list contains the values of the corresponding index of tuple T. | ||
@@ -449,7 +439,7 @@ * @param length - the length of the tuples in type T | ||
*/ | ||
unzip<L extends number, T2 extends T = T>( | ||
length: L | ||
): T2 extends readonly [unknown, ...unknown[]] & { length: L } | ||
? { [K in keyof T2]: List<T2[K]> } | ||
: never; | ||
// unzip<L extends number, T2 extends T = T>( | ||
// length: L | ||
// ): T2 extends readonly [unknown, ...unknown[]] & { length: L } | ||
// ? { [K in keyof T2]: List<T2[K]> } | ||
// : never; | ||
/** | ||
@@ -462,7 +452,7 @@ * Returns, if T is a valid `StreamSource`, the result of concatenating all | ||
*/ | ||
flatten<T2 = T>(): T2 extends StreamSource.NonEmpty<infer S> | ||
? List<S> | ||
: T2 extends StreamSource<infer S> | ||
? List<S> | ||
: never; | ||
// flatten<T2 = T>(): T2 extends StreamSource.NonEmpty<infer S> | ||
// ? List<S> | ||
// : T2 extends StreamSource<infer S> | ||
// ? List<S> | ||
// : never; | ||
} | ||
@@ -542,3 +532,5 @@ | ||
*/ | ||
concat(...sources: ArrayNonEmpty<StreamSource<T>>): List.NonEmpty<T>; | ||
concat<T2 = T>( | ||
...sources: ArrayNonEmpty<StreamSource<T2>> | ||
): List.NonEmpty<T | T2>; | ||
/** | ||
@@ -693,12 +685,2 @@ * Returns, for a List of `StreamSource` instances of type T, a List of type T containing the concatenation | ||
/** | ||
* Returns the same `List` with a wider value type T2, if T2 | ||
* is a super type of T. | ||
* @typeparam T2 - a super type of T | ||
* @example | ||
* const m = List.of(1, 2, 3) | ||
* m.extendType<number | string>() | ||
* // type: List.NonEmpty<number | string> | ||
*/ | ||
extendType<T2>(): List.NonEmpty<SuperOf<T2, T>>; | ||
/** | ||
* Returns an array of Lists, where each list contains the values of the corresponding index of tuple T. | ||
@@ -710,12 +692,12 @@ * @param length - the length of the tuples in type T | ||
*/ | ||
unzip<L extends number, T2 extends T = T>( | ||
length: L | ||
): T2 extends readonly [unknown, ...unknown[]] & { length: L } | ||
? { [K in keyof T2]: List.NonEmpty<T2[K]> } | ||
: never; | ||
flatten<T2 extends T = T>(): T2 extends StreamSource.NonEmpty<infer S> | ||
? List.NonEmpty<S> | ||
: T2 extends StreamSource<infer S> | ||
? List<S> | ||
: never; | ||
// unzip<L extends number, T2 extends T = T>( | ||
// length: L | ||
// ): T2 extends readonly [unknown, ...unknown[]] & { length: L } | ||
// ? { [K in keyof T2]: List.NonEmpty<T2[K]> } | ||
// : never; | ||
// flatten<T2 extends T = T>(): T2 extends StreamSource.NonEmpty<infer S> | ||
// ? List.NonEmpty<S> | ||
// : T2 extends StreamSource<infer S> | ||
// ? List<S> | ||
// : never; | ||
} | ||
@@ -942,2 +924,34 @@ | ||
/** | ||
* Returns, if T is a valid `StreamSource`, the result of concatenating all | ||
* streamable elements of the given sources. | ||
* @example | ||
* const m = List.of([1, 2], [3, 4, 5]) | ||
* List.flatten(m).toArray() // => [1, 2, 3, 4, 5] | ||
*/ | ||
flatten: { | ||
<T extends StreamSource.NonEmpty<unknown>>( | ||
source: StreamSource.NonEmpty<T> | ||
): T extends StreamSource.NonEmpty<infer S> ? List.NonEmpty<S> : never; | ||
<T extends StreamSource<unknown>>( | ||
source: StreamSource<T> | ||
): T extends StreamSource<infer S> ? List<S> : never; | ||
}; | ||
/** | ||
* Returns an array of Lists, where each list contains the values of the corresponding index of tuple T. | ||
* @param length - the length of the tuples in type T | ||
* @example | ||
* const m = List.of([1, 'a'], [2, 'b']) | ||
* List.unzip(m) // => [List.NonEmpty<number>, List.NonEmpty<string>] | ||
*/ | ||
unzip: { | ||
<T extends readonly unknown[] & { length: L }, L extends number>( | ||
source: StreamSource.NonEmpty<T>, | ||
length: L | ||
): { [K in keyof T]: List.NonEmpty<T[K]> }; | ||
<T extends readonly unknown[] & { length: L }, L extends number>( | ||
source: StreamSource<T>, | ||
length: L | ||
): { [K in keyof T]: List<T[K]> }; | ||
}; | ||
/** | ||
* Returns an empty List Builder based on this context. | ||
@@ -944,0 +958,0 @@ * @example |
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
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
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
723262
12137
80
+ Added@rimbu/base@0.7.2(transitive)
+ Added@rimbu/collection-types@0.8.3(transitive)
+ Added@rimbu/common@0.8.2(transitive)
+ Added@rimbu/stream@0.8.20.9.0(transitive)
- Removed@rimbu/base@0.6.7(transitive)
- Removed@rimbu/collection-types@0.7.5(transitive)
- Removed@rimbu/common@0.7.5(transitive)
- Removed@rimbu/stream@0.7.5(transitive)
Updated@rimbu/base@^0.7.0
Updated@rimbu/common@^0.8.0
Updated@rimbu/stream@^0.8.0