ts-pattern-matching
ts-pattern-matching copied to clipboard
Possibility to filter on expressions
I was wondering whether it would be possible to make a variant API that allows you to essentially leave the initial match constructor empty and to evaluate left-hand patterns. Like a more succinct case/switch:
const getActionType = (doc: DocumentApi) =>
match<Boolean, ActionType>(doc)
.with(isMutationAction, () => "Mutation")
.with(isQueryAction, () => "Query")
.otherwise(() => new Error("Neither Mutation or Query found in Document SDL"))
.run() as ActionType
Because currently, I am doing it like this, which feels a bit awkward:
const getActionType = (doc: DocumentApi) =>
match<Boolean, ActionType>(isMutationAction(doc))
.with(true, () => "Mutation")
.with(false, () => "Query")
.otherwise(() => new Error("Neither Mutation or Query found in Document SDL"))
.run() as ActionType
Thank you for such a wonderful library =D