Closed pd4d10 closed 1 year ago
You can use S.recursive
for this:
type rec t = File({content: string}) | Directory({files: array<t>})
let struct = S.recursive(struct =>
S.union([
S.object(o => {
o->S.field("tag", S.literal(String("file")))->ignore
File({content: o->S.field("content", S.string())})
}),
S.object(o => {
o->S.field("tag", S.literal(String("directory")))->ignore
Directory({files: o->S.field("files", S.array(struct))})
}),
])
)
For example: