Skip to content
New issue

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

Possibility to filter on expressions #1

Open
GavinRay97 opened this issue Apr 16, 2020 · 0 comments
Open

Possibility to filter on expressions #1

GavinRay97 opened this issue Apr 16, 2020 · 0 comments

Comments

@GavinRay97
Copy link

GavinRay97 commented Apr 16, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant