Comments (3)
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.
@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.
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)
- create initial pull request HOT 1
- publish to Bower registry HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sanctuary-either.