Giter VIP home page Giter VIP logo

caseof's Introduction

caseof

A simple way to query constructors, like cases but slightly more concise.

Aimed at sum types with many constructors:

data Wiggle = Woo Int Char | Wibble Int deriving Show

There is a case predicate:

> $(isCaseOf 'Woo) (Woo 5 'a')
True

There is a Maybe-based matcher:

> $(maybeCaseOf 'Woo) (Woo 1 'a')
Just (1,'a')

There is a "map" over a constructor:

> $(mapCaseOf 'Left) succ (Left 3)
Left 4

There is a combinator which calls your function with n arguments, or passes the whole value to an "else" clause.

> $(caseOf 'Woo) (\x y -> show x ++ show y) (const "") (Wibble 5)
""

Use in your project

In your stack.yaml, put:

extra-deps:
- git: https://github.com/chrisdone/caseof.git
  commit: 9a7f6bb

Lens prisms

For me, the lens approach (aside from being a big dependency) has these downsides: a complicated set of types and a requirement to derive prisms for the types, which enter the namespace. The downside for caseof is the TH requirement, but it is dead simple. You just read this README in 20 seconds.

caseof's People

Contributors

chrisdone avatar

Stargazers

 avatar Jay Pratt avatar Xiaoliang Zhang avatar Elliot Cameron avatar chessai avatar Sandra Dylus avatar Jonas Benn avatar Daniel Díaz Carrete avatar Byungjik Roh avatar André Bianchi avatar Joomy Korkut avatar

Watchers

 avatar James Cloos avatar  avatar  avatar

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.