fantasyland / fantasy-maybes Goto Github PK
View Code? Open in Web Editor NEWOption data structure.
Option data structure.
Hi,
I am trying to use OptionT with the State monad from fantasy-states for handling errors in stateful computations. Are there any examples that I can refer to?
Should we implement First
or Last
to allow Option
to be a Monoid?
I'm excited by the discussion in ramda/ramda-fantasy#139.
One potential problem has become apparent to me: there are two common names for this data type. Haskell uses "Maybe"; Scala uses "Option". Neither is better or worse than the other, but there are contexts in which one is more appropriate than the other. Sanctuary, for example, is strongly inspired by Haskell and PureScript so uses "Maybe", whereas Folktale draws inspiration from Scalaz and Cats (I believe), so uses "Option".
Since the goal is for this project is to be the canonical implementation of the Maybe/Option type, it would be nice if we could somehow please everyone. While someone could easily include…
const Nothing = None;
const Just = Some;
in her own code to use the "Haskell" data constructors, the string representation of Just(42)
would still be 'Some(42)'
.
I'm thinking through the ramifications of merging Sanctuary's Maybe type into this repository. Since Sanctuary is inspired by Haskell and PureScript I certainly want to keep using "Maybe" in that project, and I certainly don't want to monkey patch Option#toString
.
Perhaps this project should export both Maybe and Option:
exports.Maybe = create('Nothing', 'Just');
exports.Option = create('None', 'Some');
const {Nothing, Just} = require('fantasy-options').Maybe;
const {None, Some} = require('fantasy-options').Option;
Maybe and Option would really be two names for the same type. Just(42)
and Some(42)
would be interchangeable, though they would have different string representations.
I realize the thoughts I'm sharing are not fully formed. My goal is to start a discussion rather than to propose a specific solution.
https://github.com/fantasyland/fantasy-options/blob/master/test/option.js#L42
Not an issue with the actual library. isNone
is never actually used in the testing either, just defined. If someone stumbles upon it and uses it in their code it will just lead to confusion. In daggy.js
taggedSum
s doesn't actually create a constructor
for keys with values of zero length.
Here's my implementation of isNone
:
var isNone = function(o){
return isOption(o) && not(isSome(o))
}
I was using bilby.js
before so this confused me a little.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.