interface Box extends Pipeable {
readonly content: Content
}
// Need this to be able to nest the Box definition, since i get a type error for the pipe method
const _Box = Schema.suspend(
(): Schema.Schema<{ content: Content }> =>
Schema.Struct({
content: Content
})
)
// Contents of a box.
const Content = Schema.Union(
Schema.TaggedStruct("Blank", {}),
Schema.TaggedStruct("Text", { text: Schema.String }),
Schema.TaggedStruct("Row", {
boxes: Schema.Array(_Box)
}),
Schema.TaggedStruct("Col", {
boxes: Schema.Array(_Box)
}),
Schema.TaggedStruct("SubBox", {
box: _Box
})
)
type Content = typeof Content.Type
// Need this to inject the `pipeArgument` into
const make = (b: {
content: Content
}): Box => {
const box = {
...b
} as Box
box.pipe = function() {
return pipeArguments(this, arguments)
}
return box
}
const Box = Schema.Struct({
content: Content
})
// A @1x1@ box containing a single character.
// char :: Char -> Box
const char = (c: string): Box =>
make({
content: { _tag: "Text", text: c[0] ?? " " }
})
const foo = char("A")
const bar = foo.pipe((a) => a.content._tag)
interface Box extends Pipeable {
readonly content: Content
}
// Need this to be able to nest the Box definition, since i get a type error for the pipe method
const _Box = Schema.suspend(
(): Schema.Schema<{ content: Content }> =>
Schema.Struct({
content: Content
})
)
// Contents of a box.
const Content = Schema.Union(
Schema.TaggedStruct("Blank", {}),
Schema.TaggedStruct("Text", { text: Schema.String }),
Schema.TaggedStruct("Row", {
boxes: Schema.Array(_Box)
}),
Schema.TaggedStruct("Col", {
boxes: Schema.Array(_Box)
}),
Schema.TaggedStruct("SubBox", {
box: _Box
})
)
type Content = typeof Content.Type
// Need this to inject the `pipeArgument` into
const make = (b: {
content: Content
}): Box => {
const box = {
...b
} as Box
box.pipe = function() {
return pipeArguments(this, arguments)
}
return box
}
const Box = Schema.Struct({
content: Content
})
// A @1x1@ box containing a single character.
// char :: Char -> Box
const char = (c: string): Box =>
make({
content: { _tag: "Text", text: c[0] ?? " " }
})
const foo = char("A")
const bar = foo.pipe((a) => a.content._tag)