Giter Site home page Giter Site logo

Comments (3)

davidchambers avatar davidchambers commented on August 15, 2024 1

Another option is to provide and document the case-folding function:

either :: (a -> c) -> (b -> c) -> Either a b -> c

What do you think of this idea, @dotnetCarpenter?

from sanctuary-either.

dotnetCarpenter avatar dotnetCarpenter commented on August 15, 2024

@davidchambers Is that because you dislike Either.isLeft and Either.isRight?

Since js does not have pattern matching, both properties are extremely useful. I keep wishing fluture had something akin.

I used both a lot while developing PR#308 in sanctuary-def (not sure they are gonna stay in the finished PR though).
See line 1542 and line 1571

from sanctuary-either.

davidchambers avatar davidchambers commented on August 15, 2024

I prefer the case-folding function because it does not expose implementation details.

Here is a function-based implementation that can provide either but not isLeft and isRight properties:

//    Left :: a -> Either a b
const Left = a => left => right => left (a);

//    Right :: b -> Either a b
const Right = b => left => right => right (b);

//    either :: (a -> c) -> (b -> c) -> Either a b -> c
const either = f => g => e => e (f) (g);

//    showEither :: (Showable a, Showable b) => Either a b -> String
const showEither = either (a => 'Left (' + show (a) + ')')
                          (b => 'Right (' + show (b) + ')');

isLeft :: Either a b -> Boolean and isRight :: Either a b -> Boolean can be defined in terms of either. :)

from sanctuary-either.

Related Issues (3)

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.