import type { RMap, RSet } from '@rimbu/collection-types'; import type { Stream, Streamable } from '@rimbu/stream'; import type { ArrowGraphCreators, Link } from '@rimbu/graph/custom'; import { type ArrowGraphBase, GraphContext } from '@rimbu/graph/custom'; /** * A 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 extends ArrowGraphBase {} 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 extends ArrowGraphBase.NonEmpty, Omit, keyof ArrowGraphBase.NonEmpty>, Streamable.NonEmpty<[N] | Link> { /** * 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>; } /** * 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 extends ArrowGraphBase.Builder {} /** * 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 extends ArrowGraphBase.Context {} /** * Utility interface that provides higher-kinded types for this collection. */ export interface Types extends ArrowGraphBase.Types { readonly normal: ArrowGraph; readonly nonEmpty: ArrowGraph.NonEmpty; readonly context: ArrowGraph.Context; readonly builder: ArrowGraph.Builder; } } export const ArrowGraph: ArrowGraphCreators = Object.freeze({ createContext(options: { linkMapContext: RMap.Context; linkConnectionsContext: RSet.Context; }): ArrowGraph.Context { return Object.freeze( new GraphContext( true, 'ArrowGraph', options.linkMapContext, options.linkConnectionsContext ) ); }, });