@rimbu/collection-types
Advanced tools
Comparing version 0.6.1 to 0.7.0
@@ -5,2 +5,3 @@ "use strict"; | ||
var tslib_1 = require("tslib"); | ||
var common_1 = require("@rimbu/common"); | ||
var stream_1 = require("@rimbu/stream"); | ||
@@ -46,2 +47,12 @@ var RMapBase; | ||
}; | ||
this.reducer = function (source) { | ||
return common_1.Reducer.create(function () { | ||
return undefined === source | ||
? _this.builder() | ||
: _this.from(source).toBuilder(); | ||
}, function (builder, entry) { | ||
builder.addEntry(entry); | ||
return builder; | ||
}, function (builder) { return builder.build(); }); | ||
}; | ||
} | ||
@@ -48,0 +59,0 @@ Object.defineProperty(ContextBase.prototype, "_types", { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RSetBase = void 0; | ||
var common_1 = require("@rimbu/common"); | ||
var stream_1 = require("@rimbu/stream"); | ||
@@ -44,2 +45,12 @@ var RSetBase; | ||
}; | ||
this.reducer = function (source) { | ||
return common_1.Reducer.create(function () { | ||
return undefined === source | ||
? _this.builder() | ||
: _this.from(source).toBuilder(); | ||
}, function (builder, value) { | ||
builder.add(value); | ||
return builder; | ||
}, function (builder) { return builder.build(); }); | ||
}; | ||
} | ||
@@ -46,0 +57,0 @@ Object.defineProperty(ContextBase.prototype, "_types", { |
@@ -0,1 +1,2 @@ | ||
import { Reducer } from '@rimbu/common'; | ||
import { Stream, StreamSource } from '@rimbu/stream'; | ||
@@ -32,2 +33,10 @@ export var RMapBase; | ||
}; | ||
this.reducer = (source) => { | ||
return Reducer.create(() => undefined === source | ||
? this.builder() | ||
: this.from(source).toBuilder(), (builder, entry) => { | ||
builder.addEntry(entry); | ||
return builder; | ||
}, (builder) => builder.build()); | ||
}; | ||
} | ||
@@ -34,0 +43,0 @@ get _types() { |
@@ -0,1 +1,2 @@ | ||
import { Reducer } from '@rimbu/common'; | ||
import { StreamSource } from '@rimbu/stream'; | ||
@@ -32,2 +33,10 @@ export var RSetBase; | ||
}; | ||
this.reducer = (source) => { | ||
return Reducer.create(() => undefined === source | ||
? this.builder() | ||
: this.from(source).toBuilder(), (builder, value) => { | ||
builder.add(value); | ||
return builder; | ||
}, (builder) => builder.build()); | ||
}; | ||
} | ||
@@ -34,0 +43,0 @@ get _types() { |
import type { Token } from '@rimbu/base'; | ||
import type { ArrayNonEmpty, OptLazy, OptLazyOr, RelatedTo, SuperOf, ToJSON, TraverseState, Update } from '@rimbu/common'; | ||
import { Reducer } from '@rimbu/common'; | ||
import { FastIterable, Stream, Streamable, StreamSource } from '@rimbu/stream'; | ||
@@ -616,2 +617,13 @@ import type { KeyValue, WithKeyValue } from '../custom-base'; | ||
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']>; | ||
} | ||
@@ -798,4 +810,4 @@ export interface Builder<K, V, Tp extends RMapBase.Types = RMapBase.Types> { | ||
export abstract class ContextBase<UK, Tp extends RMapBase.Types = RMapBase.Types> implements RMapBase.Context<UK, Tp> { | ||
abstract readonly typeTag: string; | ||
abstract readonly _empty: (Tp & KeyValue<any, any>)['normal']; | ||
abstract get typeTag(): string; | ||
abstract get _empty(): (Tp & KeyValue<any, any>)['normal']; | ||
abstract isValidKey(key: any): key is UK; | ||
@@ -807,3 +819,4 @@ abstract isNonEmptyInstance<K, V>(source: any): source is WithKeyValue<Tp, K, V>['nonEmpty']; | ||
from: any; | ||
of: <K, V>(values_0: readonly [K, V], ...values_1: (readonly [K, V])[]) => K extends UK ? WithKeyValue<Tp, K, V>["nonEmpty"] : never; | ||
of: <K extends UK, V>(values_0: readonly [K, V], ...values_1: (readonly [K, V])[]) => K extends UK ? WithKeyValue<Tp, K, V>["nonEmpty"] : never; | ||
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: { | ||
@@ -810,0 +823,0 @@ [KT in keyof I]: I[KT] | O; |
import type { ArrayNonEmpty, RelatedTo, ToJSON, TraverseState } from '@rimbu/common'; | ||
import { Reducer } from '@rimbu/common'; | ||
import { FastIterable, Stream, Streamable, StreamSource } from '@rimbu/stream'; | ||
@@ -300,2 +301,13 @@ import type { Elem, WithElem } from '../custom-base'; | ||
builder: <T extends UT>() => WithElem<Tp, T>['builder']; | ||
/** | ||
* Returns a `Reducer` that appends received items to an RSet and returns the RSet as a result. When a `source` is given, | ||
* the reducer will first create an RSet from the source, and then append elements to it. | ||
* @param source - (optional) an initial source of elements to append to | ||
* @example | ||
* const someList = SortedSet.of(1, 2, 3); | ||
* const result = Stream.range({ start: 20, amount: 5 }).reduce(SortedSet.reducer(someList)) | ||
* 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>(source?: StreamSource<T>) => Reducer<T, WithElem<Tp, T>['normal']>; | ||
} | ||
@@ -397,4 +409,4 @@ export interface Builder<T, Tp extends RSetBase.Types = RSetBase.Types> { | ||
export abstract class ContextBase<UT, Tp extends RSetBase.Types = RSetBase.Types> implements RSetBase.Context<UT, Tp> { | ||
abstract readonly typeTag: string; | ||
abstract readonly _empty: (Tp & Elem<any>)['normal']; | ||
abstract get typeTag(): string; | ||
abstract get _empty(): (Tp & Elem<any>)['normal']; | ||
abstract isValidValue(value: any): value is UT; | ||
@@ -406,5 +418,6 @@ abstract isNonEmptyInstance<T>(source: any): source is WithElem<Tp, T>['nonEmpty']; | ||
from: any; | ||
of: <T>(values_0: T, ...values_1: T[]) => T extends UT ? WithElem<Tp, T>["nonEmpty"] : never; | ||
of: <T extends UT>(values_0: T, ...values_1: T[]) => T extends UT ? WithElem<Tp, T>["nonEmpty"] : never; | ||
reducer: <T extends UT>(source?: StreamSource<T> | undefined) => Reducer<T, WithElem<Tp, T>["normal"]>; | ||
} | ||
export {}; | ||
} |
{ | ||
"name": "@rimbu/collection-types", | ||
"version": "0.6.1", | ||
"version": "0.7.0", | ||
"description": "Type definitions for the basic generic Rimbu collections", | ||
@@ -55,5 +55,5 @@ "keywords": [ | ||
"dependencies": { | ||
"@rimbu/base": "^0.6.1", | ||
"@rimbu/common": "^0.6.1", | ||
"@rimbu/stream": "^0.6.1" | ||
"@rimbu/base": "^0.6.2", | ||
"@rimbu/common": "^0.7.0", | ||
"@rimbu/stream": "^0.7.0" | ||
}, | ||
@@ -66,3 +66,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "ebcf6f5f730b10fd78f14d8886e0b50eb186d5ad" | ||
"gitHead": "28453a94283b4f6bcdac1a07737b2bd58ece3658" | ||
} |
@@ -12,2 +12,3 @@ import type { Token } from '@rimbu/base'; | ||
} from '@rimbu/common'; | ||
import { Reducer } from '@rimbu/common'; | ||
import { FastIterable, Stream, Streamable, StreamSource } from '@rimbu/stream'; | ||
@@ -704,2 +705,15 @@ import type { KeyValue, WithKeyValue } from '../custom-base'; | ||
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']>; | ||
} | ||
@@ -901,4 +915,4 @@ | ||
{ | ||
abstract readonly typeTag: string; | ||
abstract readonly _empty: (Tp & KeyValue<any, any>)['normal']; | ||
abstract get typeTag(): string; | ||
abstract get _empty(): (Tp & KeyValue<any, any>)['normal']; | ||
@@ -948,3 +962,3 @@ abstract isValidKey(key: any): key is UK; | ||
of = <K, V>( | ||
of = <K extends UK, V>( | ||
...values: ArrayNonEmpty<readonly [K, V]> | ||
@@ -955,2 +969,20 @@ ): K extends UK ? WithKeyValue<Tp, K, V>['nonEmpty'] : never => { | ||
reducer = <K extends UK, V>( | ||
source?: StreamSource<readonly [K, V]> | ||
): Reducer<readonly [K, V], WithKeyValue<Tp, K, V>['normal']> => { | ||
return Reducer.create( | ||
() => | ||
undefined === source | ||
? this.builder<K, V>() | ||
: ( | ||
this.from(source) as WithKeyValue<Tp, K, V>['normal'] | ||
).toBuilder(), | ||
(builder, entry) => { | ||
builder.addEntry(entry); | ||
return builder; | ||
}, | ||
(builder) => builder.build() | ||
); | ||
}; | ||
mergeAllWith<R, K, O, I extends readonly [unknown, unknown, ...unknown[]]>( | ||
@@ -957,0 +989,0 @@ fillValue: O, |
@@ -7,2 +7,3 @@ import type { | ||
} from '@rimbu/common'; | ||
import { Reducer } from '@rimbu/common'; | ||
import { FastIterable, Stream, Streamable, StreamSource } from '@rimbu/stream'; | ||
@@ -347,2 +348,15 @@ import type { Elem, WithElem } from '../custom-base'; | ||
builder: <T extends UT>() => WithElem<Tp, T>['builder']; | ||
/** | ||
* Returns a `Reducer` that appends received items to an RSet and returns the RSet as a result. When a `source` is given, | ||
* the reducer will first create an RSet from the source, and then append elements to it. | ||
* @param source - (optional) an initial source of elements to append to | ||
* @example | ||
* const someList = SortedSet.of(1, 2, 3); | ||
* const result = Stream.range({ start: 20, amount: 5 }).reduce(SortedSet.reducer(someList)) | ||
* 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>( | ||
source?: StreamSource<T> | ||
) => Reducer<T, WithElem<Tp, T>['normal']>; | ||
} | ||
@@ -454,4 +468,4 @@ | ||
{ | ||
abstract readonly typeTag: string; | ||
abstract readonly _empty: (Tp & Elem<any>)['normal']; | ||
abstract get typeTag(): string; | ||
abstract get _empty(): (Tp & Elem<any>)['normal']; | ||
@@ -501,3 +515,3 @@ abstract isValidValue(value: any): value is UT; | ||
of = <T>( | ||
of = <T extends UT>( | ||
...values: ArrayNonEmpty<T> | ||
@@ -507,3 +521,19 @@ ): T extends UT ? WithElem<Tp, T>['nonEmpty'] : never => { | ||
}; | ||
reducer = <T extends UT>( | ||
source?: StreamSource<T> | ||
): Reducer<T, WithElem<Tp, T>['normal']> => { | ||
return Reducer.create( | ||
() => | ||
undefined === source | ||
? this.builder<T>() | ||
: (this.from(source) as WithElem<Tp, T>['normal']).toBuilder(), | ||
(builder, value) => { | ||
builder.add(value); | ||
return builder; | ||
}, | ||
(builder) => builder.build() | ||
); | ||
}; | ||
} | ||
} |
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
196632
4246
+ Added@rimbu/stream@0.7.5(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