@rimbu/table
Advanced tools
Comparing version 0.6.2 to 0.7.0
@@ -689,2 +689,12 @@ "use strict"; | ||
}; | ||
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(); }); | ||
}; | ||
} | ||
@@ -691,0 +701,0 @@ Object.defineProperty(TableContext.prototype, "_types", { |
import { RimbuError, Token } from '@rimbu/base'; | ||
import { CustomBase as CB } from '@rimbu/collection-types'; | ||
import { OptLazy, OptLazyOr, TraverseState, Update, } from '@rimbu/common'; | ||
import { OptLazy, OptLazyOr, Reducer, TraverseState, Update, } from '@rimbu/common'; | ||
import { Stream, StreamSource } from '@rimbu/stream'; | ||
@@ -620,2 +620,10 @@ export class TableEmpty extends CB.EmptyBase { | ||
}; | ||
this.reducer = (source) => { | ||
return Reducer.create(() => undefined === source | ||
? this.builder() | ||
: this.from(source).toBuilder(), (builder, entry) => { | ||
builder.addEntry(entry); | ||
return builder; | ||
}, (builder) => builder.build()); | ||
}; | ||
} | ||
@@ -622,0 +630,0 @@ get _types() { |
import { Token } from '@rimbu/base'; | ||
import { CustomBase as CB, RMap } from '@rimbu/collection-types'; | ||
import { ArrayNonEmpty, OptLazy, OptLazyOr, RelatedTo, ToJSON, TraverseState, Update } from '@rimbu/common'; | ||
import { ArrayNonEmpty, OptLazy, OptLazyOr, Reducer, RelatedTo, ToJSON, TraverseState, Update } from '@rimbu/common'; | ||
import { Stream, StreamSource } from '@rimbu/stream'; | ||
@@ -127,3 +127,4 @@ import type { Table } from '../internal'; | ||
builder: <R extends UR, C extends UC, V>() => CB.WithRow<Tp, R, C, V>["builder"]; | ||
reducer: <R extends UR, C extends UC, V>(source?: StreamSource<readonly [R, C, V]> | undefined) => Reducer<[R, C, V], CB.WithRow<Tp, R, C, V>["normal"]>; | ||
createBuilder<R extends UR, C extends UC, V>(source?: Table.NonEmpty<R, C, V>): CB.WithRow<Tp, R, C, V>['builder']; | ||
} |
import type { Token } from '@rimbu/base'; | ||
import type { CustomBase as CB, RMap, VariantMap } from '@rimbu/collection-types'; | ||
import type { ArrayNonEmpty, OptLazy, OptLazyOr, RelatedTo, SuperOf, ToJSON, TraverseState, Update } from '@rimbu/common'; | ||
import type { ArrayNonEmpty, OptLazy, OptLazyOr, Reducer, RelatedTo, SuperOf, ToJSON, TraverseState, Update } from '@rimbu/common'; | ||
import type { FastIterable, Stream, Streamable, StreamSource } from '@rimbu/stream'; | ||
@@ -528,2 +528,13 @@ export interface VariantTableBase<R, C, V, Tp extends VariantTableBase.Types = VariantTableBase.Types> extends FastIterable<[R, C, V]> { | ||
builder: <R extends UR, C extends UC, V>() => CB.WithRow<Tp, R, C, V>['builder']; | ||
/** | ||
* Returns a `Reducer` that adds received tuples to a Table and returns the Table as a result. When a `source` is given, | ||
* the reducer will first create a Table from the source, and then add tuples to it. | ||
* @param source - (optional) an initial source of tuples to add to | ||
* @example | ||
* const someSource = Table.of([1, 'a', true], [2, 'b', false]); | ||
* const result = Stream.of([1, 'c', true], [3, 'a', false]).reduce(Table.reducer(someSource)) | ||
* result.toArray() // => [[1, 'c'], [2, 'b'], [3, 'a']] | ||
* @note uses a builder under the hood. If the given `source` is a Table in the same context, it will directly call `.toBuilder()`. | ||
*/ | ||
reducer: <R extends UR, C extends UC, V>(source?: StreamSource<readonly [R, C, V]>) => Reducer<[R, C, V], CB.WithRow<Tp, R, C, V>['normal']>; | ||
} | ||
@@ -530,0 +541,0 @@ export interface Builder<R, C, V, Tp extends TableBase.Types = TableBase.Types> { |
{ | ||
"name": "@rimbu/table", | ||
"version": "0.6.2", | ||
"version": "0.7.0", | ||
"description": "Immutable spreadsheet-like data structures containing row keys, column keys, and cell values", | ||
@@ -60,8 +60,8 @@ "keywords": [ | ||
"dependencies": { | ||
"@rimbu/base": "^0.6.1", | ||
"@rimbu/collection-types": "^0.6.1", | ||
"@rimbu/common": "^0.6.1", | ||
"@rimbu/hashed": "^0.6.2", | ||
"@rimbu/sorted": "^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/hashed": "^0.6.3", | ||
"@rimbu/sorted": "^0.6.2", | ||
"@rimbu/stream": "^0.7.0" | ||
}, | ||
@@ -74,3 +74,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "4990d9a30716d3a5e7117545e5a6ced2d36ae3ad" | ||
"gitHead": "28453a94283b4f6bcdac1a07737b2bd58ece3658" | ||
} |
@@ -7,2 +7,3 @@ import { RimbuError, Token } from '@rimbu/base'; | ||
OptLazyOr, | ||
Reducer, | ||
RelatedTo, | ||
@@ -974,2 +975,20 @@ ToJSON, | ||
reducer = <R extends UR, C extends UC, V>( | ||
source?: StreamSource<readonly [R, C, V]> | ||
): Reducer<[R, C, V], CB.WithRow<Tp, R, C, V>['normal']> => { | ||
return Reducer.create( | ||
() => | ||
undefined === source | ||
? this.builder<R, C, V>() | ||
: ( | ||
this.from(source) as CB.WithRow<Tp, R, C, V>['normal'] | ||
).toBuilder(), | ||
(builder, entry) => { | ||
builder.addEntry(entry); | ||
return builder; | ||
}, | ||
(builder) => builder.build() | ||
); | ||
}; | ||
createBuilder<R extends UR, C extends UC, V>( | ||
@@ -976,0 +995,0 @@ source?: Table.NonEmpty<R, C, V> |
@@ -11,2 +11,3 @@ import type { Token } from '@rimbu/base'; | ||
OptLazyOr, | ||
Reducer, | ||
RelatedTo, | ||
@@ -670,2 +671,15 @@ SuperOf, | ||
>['builder']; | ||
/** | ||
* Returns a `Reducer` that adds received tuples to a Table and returns the Table as a result. When a `source` is given, | ||
* the reducer will first create a Table from the source, and then add tuples to it. | ||
* @param source - (optional) an initial source of tuples to add to | ||
* @example | ||
* const someSource = Table.of([1, 'a', true], [2, 'b', false]); | ||
* const result = Stream.of([1, 'c', true], [3, 'a', false]).reduce(Table.reducer(someSource)) | ||
* result.toArray() // => [[1, 'c'], [2, 'b'], [3, 'a']] | ||
* @note uses a builder under the hood. If the given `source` is a Table in the same context, it will directly call `.toBuilder()`. | ||
*/ | ||
reducer: <R extends UR, C extends UC, V>( | ||
source?: StreamSource<readonly [R, C, V]> | ||
) => Reducer<[R, C, V], CB.WithRow<Tp, R, C, V>['normal']>; | ||
} | ||
@@ -672,0 +686,0 @@ |
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
218302
4310
- 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/hashed@^0.6.3
Updated@rimbu/sorted@^0.6.2
Updated@rimbu/stream@^0.7.0