@rimbu/graph
Advanced tools
Comparing version 0.9.15 to 0.10.0
@@ -282,2 +282,14 @@ "use strict"; | ||
}; | ||
this.buildMapValues = function (mapFun) { | ||
if (undefined !== _this.source) | ||
return _this.source.mapValues(mapFun); | ||
if (_this.isEmpty) | ||
return _this.context.empty(); | ||
var linkMap = _this.linkMap | ||
.buildMapValues(function (targets, source) { | ||
return targets.buildMapValues(function (value, target) { return mapFun(value, source, target); }); | ||
}) | ||
.assumeNonEmpty(); | ||
return _this.context.createNonEmpty(linkMap, _this.connectionSize); | ||
}; | ||
if (undefined !== source) | ||
@@ -284,0 +296,0 @@ this.connectionSize = source.connectionSize; |
@@ -273,2 +273,12 @@ import { RimbuError } from '@rimbu/base'; | ||
}; | ||
this.buildMapValues = (mapFun) => { | ||
if (undefined !== this.source) | ||
return this.source.mapValues(mapFun); | ||
if (this.isEmpty) | ||
return this.context.empty(); | ||
const linkMap = this.linkMap | ||
.buildMapValues((targets, source) => targets.buildMapValues((value, target) => mapFun(value, source, target))) | ||
.assumeNonEmpty(); | ||
return this.context.createNonEmpty(linkMap, this.connectionSize); | ||
}; | ||
if (undefined !== source) | ||
@@ -275,0 +285,0 @@ this.connectionSize = source.connectionSize; |
@@ -41,2 +41,3 @@ import { Token } from '@rimbu/base'; | ||
build: () => TpG['normal']; | ||
buildMapValues: <V2>(mapFun: (value: V, node1: N, node2: N) => V2) => WithGraphValues<Tp, N, V2>["normal"]; | ||
} |
@@ -360,2 +360,15 @@ import type { Token } from '@rimbu/base'; | ||
build(): WithGraphValues<Tp, N, V>['normal']; | ||
/** | ||
* Returns an immutable graph containing the nodes and connections of this builder, where the values are mapped | ||
* using the given `mapFun` function. | ||
* @param mapFun - a function taking the value | ||
* @example | ||
* ```ts | ||
* const b = ArrowValuedGraphHashed | ||
* .of([[1, 2, 'a'], [2, 3, 'b']]) | ||
* .toBuilder() | ||
* const g: ArrowValuedGraphHashed<number, string> = b.buildMapValues(v => v.toUpperCase()) | ||
* ``` | ||
*/ | ||
buildMapValues<V2>(mapFun: (value: V, node1: N, node2: N) => V2): WithGraphValues<Tp, N, V2>['normal']; | ||
} | ||
@@ -362,0 +375,0 @@ interface Factory<Tp extends ValuedGraphBase.Types, UN = unknown> { |
{ | ||
"name": "@rimbu/graph", | ||
"version": "0.9.15", | ||
"version": "0.10.0", | ||
"description": "Immutable Graph data structures for TypeScript", | ||
@@ -69,7 +69,7 @@ "keywords": [ | ||
"dependencies": { | ||
"@rimbu/collection-types": "^0.9.12", | ||
"@rimbu/common": "^0.9.4", | ||
"@rimbu/hashed": "^0.8.14", | ||
"@rimbu/sorted": "^0.9.12", | ||
"@rimbu/stream": "^0.10.12", | ||
"@rimbu/collection-types": "^0.9.13", | ||
"@rimbu/common": "^0.10.0", | ||
"@rimbu/hashed": "^0.8.15", | ||
"@rimbu/sorted": "^0.9.13", | ||
"@rimbu/stream": "^0.11.0", | ||
"tslib": "^2.4.0" | ||
@@ -91,3 +91,3 @@ }, | ||
}, | ||
"gitHead": "60d3b52050fc30f10921cbf92d637362d663d7e0" | ||
"gitHead": "4d6b7411c36f599331185b1bc597e58f34954d1a" | ||
} |
@@ -419,2 +419,18 @@ import { RimbuError, Token } from '@rimbu/base'; | ||
}; | ||
buildMapValues = <V2>( | ||
mapFun: (value: V, node1: N, node2: N) => V2 | ||
): WithGraphValues<Tp, N, V2>['normal'] => { | ||
if (undefined !== this.source) return this.source.mapValues(mapFun) as any; | ||
if (this.isEmpty) return this.context.empty<N, V2>(); | ||
const linkMap = this.linkMap | ||
.buildMapValues((targets, source) => | ||
targets.buildMapValues((value, target) => mapFun(value, source, target)) | ||
) | ||
.assumeNonEmpty(); | ||
return this.context.createNonEmpty(linkMap, this.connectionSize) as any; | ||
}; | ||
} |
@@ -427,2 +427,17 @@ import type { Token } from '@rimbu/base'; | ||
build(): WithGraphValues<Tp, N, V>['normal']; | ||
/** | ||
* Returns an immutable graph containing the nodes and connections of this builder, where the values are mapped | ||
* using the given `mapFun` function. | ||
* @param mapFun - a function taking the value | ||
* @example | ||
* ```ts | ||
* const b = ArrowValuedGraphHashed | ||
* .of([[1, 2, 'a'], [2, 3, 'b']]) | ||
* .toBuilder() | ||
* const g: ArrowValuedGraphHashed<number, string> = b.buildMapValues(v => v.toUpperCase()) | ||
* ``` | ||
*/ | ||
buildMapValues<V2>( | ||
mapFun: (value: V, node1: N, node2: N) => V2 | ||
): WithGraphValues<Tp, N, V2>['normal']; | ||
} | ||
@@ -429,0 +444,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
660693
12603
+ Added@rimbu/stream@0.11.0(transitive)
- Removed@rimbu/common@0.9.4(transitive)
- Removed@rimbu/stream@0.10.12(transitive)
Updated@rimbu/common@^0.10.0
Updated@rimbu/hashed@^0.8.15
Updated@rimbu/sorted@^0.9.13
Updated@rimbu/stream@^0.11.0