MCPcopy Create free account
hub / github.com/Effect-TS/effect / graphToArbitrary

Function graphToArbitrary

packages/effect/src/Schema.ts:15689–15717  ·  view source on GitHub ↗
(
  type: T,
  node: Codec<N>,
  edge: Codec<E>
)

Source from the content-addressed store, hash-verified

15687 readonly edges: ReadonlyArray<readonly [source: number, target: number, data: E]>
15688}
15689function 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 *

Callers 1

GraphFunction · 0.85

Calls 7

linkDecodingFunction · 0.85
NonEmptyArrayInterface · 0.85
UnionFunction · 0.70
StructFunction · 0.70
TupleFunction · 0.70
transformMethod · 0.65
mapMethod · 0.45

Tested by

no test coverage detected