-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
arrow-valued-graph.ts
89 lines (81 loc) · 3.42 KB
/
arrow-valued-graph.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import type { RMap } from '../../../../../collection-types/mod.ts';
import type { Stream, Streamable } from '../../../../../stream/mod.ts';
import type {
ArrowValuedGraphCreators,
ValuedGraphElement,
} from '../../../../../graph/custom/index.ts';
import {
type ArrowValuedGraphBase,
ValuedGraphContext,
} from '../../../../../graph/custom/index.ts';
/**
* An type-invariant immutable valued arrow (directed) graph.
* See the [Graph documentation](https://rimbu.org/docs/collections/graph) and the [ArrowValuedGraph API documentation](https://rimbu.org/api/rimbu/graph/ArrowValuedGraph/interface)
* @typeparam N - the node type
* @typeparam V - the connection value type
*/
export interface ArrowValuedGraph<N, V>
extends ArrowValuedGraphBase<N, V, ArrowValuedGraph.Types> {}
export namespace ArrowValuedGraph {
/**
* A non-empty type-invariant immutable valued arrow (directed) graph.
* See the [Graph documentation](https://rimbu.org/docs/collections/graph) and the [ArrowValuedGraph API documentation](https://rimbu.org/api/rimbu/graph/ArrowValuedGraph/interface)
* @typeparam N - the node type
* @typeparam V - the connection value type
*/
export interface NonEmpty<N, V>
extends ArrowValuedGraphBase.NonEmpty<N, V, ArrowValuedGraph.Types>,
Omit<
ArrowValuedGraph<N, V>,
keyof ArrowValuedGraphBase.NonEmpty<any, any, any>
>,
Streamable.NonEmpty<ValuedGraphElement<N, V>> {
/**
* Returns a non-empty Stream containing all entries of this collection as tuples of key and value.
* @example
* ```ts
* ArrowValuedGraphHashed.of([1, 2, 'a'], [2, 3, 'b']).stream().toArray()
* // => [[1, 2, 'a'], [2, 3, 'b']]
* ```
*/
stream(): Stream.NonEmpty<ValuedGraphElement<N, V>>;
}
/**
* A mutable `ArrowValuedGraph` builder used to efficiently create new immutable instances.
* See the [Graph documentation](https://rimbu.org/docs/collections/graph) and the [ArrowValuedGraph.Builder API documentation](https://rimbu.org/api/rimbu/graph/ArrowValuedGraph/Builder/interface)
* @typeparam N - the node type
* @typeparam V - the connection value type
*/
export interface Builder<N, V>
extends ArrowValuedGraphBase.Builder<N, V, ArrowValuedGraph.Types> {}
/**
* The ArrowValuedGraph's Context instance that serves as a factory for all related immutable instances and builders.
* @typeparam UN - the upper type limit for node types for which this context can create instances
*/
export interface Context<UN>
extends ArrowValuedGraphBase.Context<UN, ArrowValuedGraph.Types> {}
/**
* Utility interface that provides higher-kinded types for this collection.
*/
export interface Types extends ArrowValuedGraphBase.Types {
readonly normal: ArrowValuedGraph<this['_N'], this['_V']>;
readonly nonEmpty: ArrowValuedGraph.NonEmpty<this['_N'], this['_V']>;
readonly context: ArrowValuedGraph.Context<this['_N']>;
readonly builder: ArrowValuedGraph.Builder<this['_N'], this['_V']>;
}
}
export const ArrowValuedGraph: ArrowValuedGraphCreators = Object.freeze({
createContext<UN>(options: {
linkMapContext: RMap.Context<UN>;
linkConnectionsContext: RMap.Context<UN>;
}): ArrowValuedGraph.Context<UN> {
return Object.freeze(
new ValuedGraphContext<UN, 'ArrowValuedGraph', any>(
true,
'ArrowValuedGraph',
options.linkMapContext,
options.linkConnectionsContext
)
);
},
});