const withTag = (tag: string) => <Fields extends S.Struct.Fields>(from: S.Struct<Fields>) => S.transform(
S.Struct({ ...from.fields, _tag: S.tag(tag) }),
{
decode: (x) => ({ ...x, _tag: tag }),
encode: ({ _tag: _, ...rest }) => rest
}
)
const withTag = (tag: string) => <Fields extends S.Struct.Fields>(from: S.Struct<Fields>) => S.transform(
S.Struct({ ...from.fields, _tag: S.tag(tag) }),
{
decode: (x) => ({ ...x, _tag: tag }),
encode: ({ _tag: _, ...rest }) => rest
}
)