@rimbu/list
Advanced tools
Comparing version 0.6.2 to 0.7.0
@@ -6,2 +6,3 @@ "use strict"; | ||
var base_1 = require("@rimbu/base"); | ||
var common_1 = require("@rimbu/common"); | ||
var stream_1 = require("@rimbu/stream"); | ||
@@ -78,2 +79,12 @@ var list_custom_1 = require("./list-custom"); | ||
}; | ||
this.reducer = function (source) { | ||
return common_1.Reducer.create(function () { | ||
return undefined === source | ||
? _this.builder() | ||
: _this.from(source).toBuilder(); | ||
}, function (builder, value) { | ||
builder.append(value); | ||
return builder; | ||
}, function (builder) { return builder.build(); }); | ||
}; | ||
if (blockSizeBits < 2) { | ||
@@ -80,0 +91,0 @@ base_1.RimbuError.throwInvalidUsageError('List: blockSizeBits should be at least 2'); |
import { RimbuError } from '@rimbu/base'; | ||
import { Reducer } from '@rimbu/common'; | ||
import { StreamSource } from '@rimbu/stream'; | ||
@@ -60,2 +61,10 @@ import { Empty, GenBuilder, LeafBlock, LeafBlockBuilder, LeafTree, LeafTreeBuilder, ListNonEmptyBase, NonLeafBlock, NonLeafBlockBuilder, NonLeafTree, NonLeafTreeBuilder, ReversedLeafBlock, } from './list-custom'; | ||
}; | ||
this.reducer = (source) => { | ||
return Reducer.create(() => undefined === source | ||
? this.builder() | ||
: this.from(source).toBuilder(), (builder, value) => { | ||
builder.append(value); | ||
return builder; | ||
}, (builder) => builder.build()); | ||
}; | ||
if (blockSizeBits < 2) { | ||
@@ -62,0 +71,0 @@ RimbuError.throwInvalidUsageError('List: blockSizeBits should be at least 2'); |
import { OptLazy, TraverseState, Update } from '@rimbu/common'; | ||
import type { BlockBuilder, BuilderBase, LeafBlockBuilder, LeafBuilder, LeafTree, ListContext, NonLeafBlockBuilder, NonLeafBuilder, NonLeafTree } from '../../list-custom'; | ||
export declare abstract class TreeBuilderBase<T, C> { | ||
abstract readonly context: ListContext; | ||
abstract readonly level: number; | ||
abstract get context(): ListContext; | ||
abstract get level(): number; | ||
abstract get left(): BlockBuilder<T, C>; | ||
@@ -12,3 +12,4 @@ abstract set left(value: BlockBuilder<T, C>); | ||
abstract set middle(value: NonLeafBuilder<T, BlockBuilder<T, C>> | undefined); | ||
abstract length: number; | ||
abstract get length(): number; | ||
abstract set length(value: number); | ||
abstract getChildLength(child: C): number; | ||
@@ -15,0 +16,0 @@ get<O>(index: number, otherwise?: OptLazy<O>): T | O; |
@@ -0,1 +1,2 @@ | ||
import { Reducer } from '@rimbu/common'; | ||
import { StreamSource } from '@rimbu/stream'; | ||
@@ -19,2 +20,3 @@ import type { List } from './internal'; | ||
fromString: (sources_0: string, ...sources_1: string[]) => any; | ||
reducer: <T>(source?: StreamSource<T> | undefined) => Reducer<T, List<T>>; | ||
leafBlock<T>(children: readonly T[]): LeafBlock<T>; | ||
@@ -21,0 +23,0 @@ reversedLeaf<T>(children: readonly T[]): ReversedLeafBlock<T>; |
@@ -7,4 +7,4 @@ import { CustomBase } from '@rimbu/collection-types'; | ||
export declare abstract class ListNonEmptyBase<T> extends CustomBase.NonEmptyBase<T> implements List.NonEmpty<T> { | ||
abstract readonly context: ListContext; | ||
abstract readonly length: number; | ||
abstract get context(): ListContext; | ||
abstract get length(): number; | ||
abstract stream(reversed?: boolean): Stream.NonEmpty<T>; | ||
@@ -11,0 +11,0 @@ abstract streamRange(range: IndexRange, reversed?: boolean): Stream<T>; |
import type { CustomBase } from '@rimbu/collection-types'; | ||
import type { ArrayNonEmpty, CollectFun, IndexRange, OmitStrong, OptLazy, StringNonEmpty, SuperOf, ToJSON, TraverseState, Update } from '@rimbu/common'; | ||
import type { ArrayNonEmpty, CollectFun, IndexRange, OmitStrong, OptLazy, Reducer, StringNonEmpty, SuperOf, ToJSON, TraverseState, Update } from '@rimbu/common'; | ||
import type { FastIterable, Stream, Streamable, StreamSource } from '@rimbu/stream'; | ||
@@ -289,3 +289,3 @@ /** | ||
* * `halt`: a function that, when called, ensures no next elements are passed | ||
* @param range - (default: undefined) the range of the list to include in the filtering process | ||
* @param range - (optional) the range of the list to include in the filtering process | ||
* @param reversed - (default: false) if true reverses the elements within the given range | ||
@@ -309,3 +309,3 @@ * @example | ||
* * `halt`: a function that, when called, ensures no next elements are passed | ||
* @param range - (default: undefined) the range of the list to include in the filtering process | ||
* @param range - (optional) the range of the list to include in the filtering process | ||
* @param reversed - (default: false) if true reverses the elements within the given range | ||
@@ -351,3 +351,3 @@ * @example | ||
* of value to include in the resulting collection | ||
* @param range - (default: undefined) the range of the list to include in the filtering process | ||
* @param range - (optional) the range of the list to include in the filtering process | ||
* @param reversed - (default: false) if true reverses the elements within the given range | ||
@@ -366,3 +366,3 @@ */ | ||
* If `reversed` is true, reverses the order of the values. | ||
* @param range - (default: undefined) the range of the list to include in the filtering process | ||
* @param range - (optional) the range of the list to include in the filtering process | ||
* @param reversed - (default: false) if true reverses the elements within the given range | ||
@@ -530,3 +530,3 @@ * @example | ||
* @param fill - the element used to fill up empty space in the resulting List | ||
* @param positionPercentage - a percentage indicating how much of the filling elements should be on the left | ||
* @param positionPercentage - (optional) a percentage indicating how much of the filling elements should be on the left | ||
* side of the current List | ||
@@ -581,3 +581,3 @@ * @example | ||
* of value to include in the resulting collection | ||
* @param range - (default: undefined) the range of the list to include in the filtering process | ||
* @param range - (optional) the range of the list to include in the filtering process | ||
* @param reversed - (default: false) if true reverses the elements within the given range | ||
@@ -623,3 +623,3 @@ */ | ||
* If `reversed` is true, reverses the order of the values. | ||
* @param range - (default: undefined) the range of the list to include in the filtering process | ||
* @param range - (optional) the range of the list to include in the filtering process | ||
* @param reversed - (default: false) if true reverses the elements within the given range | ||
@@ -873,2 +873,13 @@ * @example | ||
builder<T>(): List.Builder<T>; | ||
/** | ||
* Returns a `Reducer` that appends received items to a List and returns the List as a result. When a `source` is given, | ||
* the reducer will first create a List from the source, and then append elements to it. | ||
* @param source - (optional) an initial source of elements to append to | ||
* @example | ||
* const someList = List.of(1, 2, 3); | ||
* const result = Stream.range({ start: 20, amount: 5 }).reduce(List.reducer(someList)) | ||
* result.toArray() // => [1, 2, 3, 20, 21, 22, 23, 24] | ||
* @note uses a List builder under the hood. If the given `source` is a List in the same context, it will directly call `.toBuilder()`. | ||
*/ | ||
reducer<T>(source?: StreamSource<T>): Reducer<T, List<T>>; | ||
} | ||
@@ -875,0 +886,0 @@ interface Types extends CustomBase.Elem { |
{ | ||
"name": "@rimbu/list", | ||
"version": "0.6.2", | ||
"version": "0.7.0", | ||
"description": "An efficient immutable ordered sequence of elements akin to a Vector", | ||
@@ -62,6 +62,6 @@ "keywords": [ | ||
"dependencies": { | ||
"@rimbu/base": "^0.6.1", | ||
"@rimbu/collection-types": "^0.6.1", | ||
"@rimbu/common": "^0.6.1", | ||
"@rimbu/stream": "^0.6.1" | ||
"@rimbu/base": "^0.6.2", | ||
"@rimbu/collection-types": "^0.7.0", | ||
"@rimbu/common": "^0.7.0", | ||
"@rimbu/stream": "^0.7.0" | ||
}, | ||
@@ -74,3 +74,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "4990d9a30716d3a5e7117545e5a6ced2d36ae3ad" | ||
"gitHead": "28453a94283b4f6bcdac1a07737b2bd58ece3658" | ||
} |
@@ -16,4 +16,4 @@ import { OptLazy, TraverseState, Update } from '@rimbu/common'; | ||
export abstract class TreeBuilderBase<T, C> { | ||
abstract readonly context: ListContext; | ||
abstract readonly level: number; | ||
abstract get context(): ListContext; | ||
abstract get level(): number; | ||
abstract get left(): BlockBuilder<T, C>; | ||
@@ -25,3 +25,4 @@ abstract set left(value: BlockBuilder<T, C>); | ||
abstract set middle(value: NonLeafBuilder<T, BlockBuilder<T, C>> | undefined); | ||
abstract length: number; | ||
abstract get length(): number; | ||
abstract set length(value: number); | ||
abstract getChildLength(child: C): number; | ||
@@ -28,0 +29,0 @@ |
import { RimbuError } from '@rimbu/base'; | ||
import type { ArrayNonEmpty } from '@rimbu/common'; | ||
import { Reducer } from '@rimbu/common'; | ||
import { StreamSource } from '@rimbu/stream'; | ||
@@ -123,2 +124,16 @@ import type { List } from './internal'; | ||
reducer = <T>(source?: StreamSource<T>): Reducer<T, List<T>> => { | ||
return Reducer.create( | ||
() => | ||
undefined === source | ||
? this.builder<T>() | ||
: this.from(source).toBuilder(), | ||
(builder, value) => { | ||
builder.append(value); | ||
return builder; | ||
}, | ||
(builder) => builder.build() | ||
); | ||
}; | ||
leafBlock<T>(children: readonly T[]): LeafBlock<T> { | ||
@@ -125,0 +140,0 @@ return new LeafBlock(this, children); |
@@ -32,4 +32,4 @@ import { Arr, RimbuError } from '@rimbu/base'; | ||
{ | ||
abstract readonly context: ListContext; | ||
abstract readonly length: number; | ||
abstract get context(): ListContext; | ||
abstract get length(): number; | ||
abstract stream(reversed?: boolean): Stream.NonEmpty<T>; | ||
@@ -36,0 +36,0 @@ abstract streamRange(range: IndexRange, reversed?: boolean): Stream<T>; |
@@ -8,2 +8,3 @@ import type { CustomBase } from '@rimbu/collection-types'; | ||
OptLazy, | ||
Reducer, | ||
StringNonEmpty, | ||
@@ -308,3 +309,3 @@ SuperOf, | ||
* * `halt`: a function that, when called, ensures no next elements are passed | ||
* @param range - (default: undefined) the range of the list to include in the filtering process | ||
* @param range - (optional) the range of the list to include in the filtering process | ||
* @param reversed - (default: false) if true reverses the elements within the given range | ||
@@ -332,3 +333,3 @@ * @example | ||
* * `halt`: a function that, when called, ensures no next elements are passed | ||
* @param range - (default: undefined) the range of the list to include in the filtering process | ||
* @param range - (optional) the range of the list to include in the filtering process | ||
* @param reversed - (default: false) if true reverses the elements within the given range | ||
@@ -384,3 +385,3 @@ * @example | ||
* of value to include in the resulting collection | ||
* @param range - (default: undefined) the range of the list to include in the filtering process | ||
* @param range - (optional) the range of the list to include in the filtering process | ||
* @param reversed - (default: false) if true reverses the elements within the given range | ||
@@ -403,3 +404,3 @@ */ | ||
* If `reversed` is true, reverses the order of the values. | ||
* @param range - (default: undefined) the range of the list to include in the filtering process | ||
* @param range - (optional) the range of the list to include in the filtering process | ||
* @param reversed - (default: false) if true reverses the elements within the given range | ||
@@ -573,3 +574,3 @@ * @example | ||
* @param fill - the element used to fill up empty space in the resulting List | ||
* @param positionPercentage - a percentage indicating how much of the filling elements should be on the left | ||
* @param positionPercentage - (optional) a percentage indicating how much of the filling elements should be on the left | ||
* side of the current List | ||
@@ -631,3 +632,3 @@ * @example | ||
* of value to include in the resulting collection | ||
* @param range - (default: undefined) the range of the list to include in the filtering process | ||
* @param range - (optional) the range of the list to include in the filtering process | ||
* @param reversed - (default: false) if true reverses the elements within the given range | ||
@@ -681,3 +682,3 @@ */ | ||
* If `reversed` is true, reverses the order of the values. | ||
* @param range - (default: undefined) the range of the list to include in the filtering process | ||
* @param range - (optional) the range of the list to include in the filtering process | ||
* @param reversed - (default: false) if true reverses the elements within the given range | ||
@@ -946,2 +947,13 @@ * @example | ||
builder<T>(): List.Builder<T>; | ||
/** | ||
* Returns a `Reducer` that appends received items to a List and returns the List as a result. When a `source` is given, | ||
* the reducer will first create a List from the source, and then append elements to it. | ||
* @param source - (optional) an initial source of elements to append to | ||
* @example | ||
* const someList = List.of(1, 2, 3); | ||
* const result = Stream.range({ start: 20, amount: 5 }).reduce(List.reducer(someList)) | ||
* result.toArray() // => [1, 2, 3, 20, 21, 22, 23, 24] | ||
* @note uses a List builder under the hood. If the given `source` is a List in the same context, it will directly call `.toBuilder()`. | ||
*/ | ||
reducer<T>(source?: StreamSource<T>): Reducer<T, List<T>>; | ||
} | ||
@@ -948,0 +960,0 @@ |
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
722877
12171
+ Added@rimbu/collection-types@0.7.5(transitive)
+ Added@rimbu/stream@0.7.5(transitive)
- Removed@rimbu/collection-types@0.6.1(transitive)
- Removed@rimbu/common@0.6.1(transitive)
- Removed@rimbu/stream@0.6.1(transitive)
Updated@rimbu/base@^0.6.2
Updated@rimbu/common@^0.7.0
Updated@rimbu/stream@^0.7.0