( type: T, node: Codec<N>, edge: Codec<E> )
| 15687 | readonly edges: ReadonlyArray<readonly [source: number, target: number, data: E]> |
| 15688 | } |
| 15689 | function graphToArbitrary<N, E, T extends Graph_.Kind>( |
| 15690 | type: T, |
| 15691 | node: Codec<N>, |
| 15692 | edge: Codec<E> |
| 15693 | ) { |
| 15694 | return linkDecoding<Graph_.Graph<N, E, T>>()( |
| 15695 | Union([ |
| 15696 | Null, |
| 15697 | Struct({ |
| 15698 | nodes: NonEmptyArray(node), |
| 15699 | edges: ArraySchema(Tuple([Natural, Natural, edge])) |
| 15700 | }) |
| 15701 | ]), |
| 15702 | SchemaGetter.transform<Graph_.Graph<N, E, T>, GraphArbitraryRepresentation<N, E>>((input) => { |
| 15703 | if (input === null) return InternalGraph.hydrate({ type, nodes: [], edges: [] }) |
| 15704 | const nodes = input.nodes.map((data, index) => ({ index, data })) |
| 15705 | return InternalGraph.hydrate({ |
| 15706 | type, |
| 15707 | nodes, |
| 15708 | edges: input.edges.map(([source, target, data], index) => ({ |
| 15709 | index, |
| 15710 | source: source % nodes.length, |
| 15711 | target: target % nodes.length, |
| 15712 | data |
| 15713 | })) |
| 15714 | }) |
| 15715 | }) |
| 15716 | ) |
| 15717 | } |
| 15718 | /** |
| 15719 | * Creates a schema for immutable directed or undirected Effect graphs. |
| 15720 | * |
no test coverage detected