-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
arrow-graph.ts
76 lines (68 loc) · 2.98 KB
/
arrow-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
import type { RMap, RSet } from '../../../../../collection-types/mod.ts';
import type { Stream, Streamable } from '../../../../../stream/mod.ts';
import type { ArrowGraphCreators, Link } from '../../../../../graph/custom/index.ts';
import { type ArrowGraphBase, GraphContext } from '../../../../../graph/custom/index.ts';
/**
* An type-invariant immutable arrow (directed) graph.
* See the [Graph documentation](https://rimbu.org/docs/collections/graph) and the [ArrowGraph API documentation](https://rimbu.org/api/rimbu/graph/ArrowGraph/interface)
* @typeparam N - the node type
*/
export interface ArrowGraph<N> extends ArrowGraphBase<N, ArrowGraph.Types> {}
export namespace ArrowGraph {
/**
* A non-empty type-invariant immutable arrow (directed) graph.
* See the [Graph documentation](https://rimbu.org/docs/collections/graph) and the [ArrowGraph API documentation](https://rimbu.org/api/rimbu/graph/ArrowGraph/interface)
* @typeparam N - the node type
*/
export interface NonEmpty<N>
extends ArrowGraphBase.NonEmpty<N, ArrowGraph.Types>,
Omit<ArrowGraph<N>, keyof ArrowGraphBase.NonEmpty<any, any>>,
Streamable.NonEmpty<[N] | Link<N>> {
/**
* Returns a non-empty `Stream` containing all graph elements of this collection as single tuples for isolated nodes
* and 2-valued tuples of nodes for connections.
* @example
* ```ts
* ArrowGraphHashed.of([1], [2, 3]).stream().toArray() // => [[1], [2, 3]]
* ```
*/
stream(): Stream.NonEmpty<[N] | Link<N>>;
}
/**
* A mutable `ArrowGraph` builder used to efficiently create new immutable instances.
* See the [Graph documentation](https://rimbu.org/docs/collections/graph) and the [ArrowGraph.Builder API documentation](https://rimbu.org/api/rimbu/graph/ArrowGraph/Builder/interface)
* @typeparam N - the node type
*/
export interface Builder<N>
extends ArrowGraphBase.Builder<N, ArrowGraph.Types> {}
/**
* The ArrowGraph'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 ArrowGraphBase.Context<UN, ArrowGraph.Types> {}
/**
* Utility interface that provides higher-kinded types for this collection.
*/
export interface Types extends ArrowGraphBase.Types {
readonly normal: ArrowGraph<this['_N']>;
readonly nonEmpty: ArrowGraph.NonEmpty<this['_N']>;
readonly context: ArrowGraph.Context<this['_N']>;
readonly builder: ArrowGraph.Builder<this['_N']>;
}
}
export const ArrowGraph: ArrowGraphCreators = Object.freeze({
createContext<UN>(options: {
linkMapContext: RMap.Context<UN>;
linkConnectionsContext: RSet.Context<UN>;
}): ArrowGraph.Context<UN> {
return Object.freeze(
new GraphContext<UN, 'ArrowGraph', true, any>(
true,
'ArrowGraph',
options.linkMapContext,
options.linkConnectionsContext
)
);
},
});