// INCOMPLETE CODE
// SHORTENED TO ILLUSTRATE QUESTION,
// which is near the bottom
// FROM
type InputNode = {
name: string // unique
parentNodes: string[] // refers to other InputNode names
}
type InputNodeList = readonly InputNode []
// TO
type Node = {
id: NodeID // Branded Type
data: InputNode
… // maybe more later on
}
type Link = { source: NodeID, target: NodeID }
const _Graph = S.struct({ nodes: S.array(Node) , links: S.array(Link) })
const Graph = transform(
InputNodeList,
_Grapth,
// QUESTION HERE
iNodeList => {
// 1. Have to decode the Node List first in order to,
// 2. derive the the Link list from it
// here is my first try using an Either:
const nodes = S.decodeEither(S.array(Node))(iNodeList);
nodes.pipe(E.flatMap(ns => /* decode more here */ ))
// HOW TO HANDLE ERRORS HERE?
// throw an error??
},
…
)
// INCOMPLETE CODE
// SHORTENED TO ILLUSTRATE QUESTION,
// which is near the bottom
// FROM
type InputNode = {
name: string // unique
parentNodes: string[] // refers to other InputNode names
}
type InputNodeList = readonly InputNode []
// TO
type Node = {
id: NodeID // Branded Type
data: InputNode
… // maybe more later on
}
type Link = { source: NodeID, target: NodeID }
const _Graph = S.struct({ nodes: S.array(Node) , links: S.array(Link) })
const Graph = transform(
InputNodeList,
_Grapth,
// QUESTION HERE
iNodeList => {
// 1. Have to decode the Node List first in order to,
// 2. derive the the Link list from it
// here is my first try using an Either:
const nodes = S.decodeEither(S.array(Node))(iNodeList);
nodes.pipe(E.flatMap(ns => /* decode more here */ ))
// HOW TO HANDLE ERRORS HERE?
// throw an error??
},
…
)