Giter Site home page Giter Site logo

wimjongeneel / ts-pattern-matching Goto Github PK

View Code? Open in Web Editor NEW
67.0 3.0 5.0 149 KB

Pattern matching in TS with Record Patterns, Type Patterns, type inference and more

Home Page: https://medium.com/@wim.jongeneel1/pattern-matching-in-typescript-with-record-and-wildcard-patterns-6097dd4e471d

TypeScript 100.00%
typescript pattern-matching typesafety functional-programming

ts-pattern-matching's People

Contributors

wimjongeneel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ts-pattern-matching's Issues

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.