We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
matchSum
Sometimes the name of the tag can be used as the lookup value in the struct. It's similar to fromSum in io-ts/Encoder.
fromSum
io-ts/Encoder
It basically looks up the value from the sum identifier.
These types don't assume a default case currently.
declare function matchSum<S extends string>( sum: S, ): < A extends Record<S, string>, M extends { [P in A[S]]: ( value: Extract<A, Record<S, P> & Record<P, unknown>>[P], ) => unknown }, >( matcher: M, ) => (fa: A) => ReturnType<M[keyof M]> declare const sumType: | { _tag: "aside"; aside: string } | { _tag: "bside"; bside: number } // boolean | null const sum = pipe( sumType, matchSum("_tag")({ aside: (string) => true, bside: (number) => null, }), )
What are your thoughts on this, happy to accept this?
The text was updated successfully, but these errors were encountered:
We can also derive some functions using these examples: https://serde.rs/enum-representations.html
Sorry, something went wrong.
Hey, @waynevanson thanks a lot for the effort and the interest you showed in this! Really appreciated! 🙏
Sadly I don't have time to follow this project at the moment 😞
If you want to open a draft PR you are more than welcome but before starting I wanted you to know that I've no idea when I will be able to review it
stefano-regosa-deel
No branches or pull requests
Sometimes the name of the tag can be used as the lookup value in the struct. It's similar to
fromSum
inio-ts/Encoder
.It basically looks up the value from the sum identifier.
These types don't assume a default case currently.
What are your thoughts on this, happy to accept this?
The text was updated successfully, but these errors were encountered: