-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[email protected] compatibility #131
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,5 +125,10 @@ Either.Left = function(value) { | |
return new _Left(value); | ||
}; | ||
|
||
require('./internal/fl-patch.js')([ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency let's drop |
||
Either, Either.prototype, | ||
_Left, _Left.prototype, | ||
_Right, _Right.prototype, | ||
]); | ||
|
||
module.exports = Either; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
var curry = require('ramda/src/curry'); | ||
var Z = require('sanctuary-type-classes'); | ||
|
||
var Identity = require('./Identity'); | ||
var Tuple = require('./Tuple'); | ||
var util = require('./internal/util'); | ||
|
||
var patchAll = require('./internal/fl-patch.js'); | ||
|
||
function T(M) { | ||
function StateT(run) { | ||
|
@@ -24,56 +25,59 @@ function T(M) { | |
StateT.prototype.chain = function(f) { | ||
var state = this; | ||
return StateT(function(s) { | ||
return state._run(s).chain(function(t) { | ||
return Z.chain(function(t) { | ||
return f(Tuple.fst(t))._run(Tuple.snd(t)); | ||
}); | ||
}, state._run(s)); | ||
}); | ||
}; | ||
StateT.of = StateT.prototype.of = function(a) { | ||
return StateT(function (s) { | ||
return M.of(Tuple(a, s)); | ||
return Z.of(M,Tuple(a, s)); | ||
}); | ||
}; | ||
StateT.prototype.ap = util.deriveAp(StateT); | ||
StateT.prototype.map = util.deriveMap(StateT); | ||
StateT.tailRec = curry(function(stepFn, init) { | ||
return StateT(function(s) { | ||
return M.tailRec(function(t) { | ||
return stepFn(Tuple.fst(t))._run(Tuple.snd(t)).chain(function (t_) { | ||
return M.of(Tuple.fst(t_).bimap( | ||
return Z.chain(function (t_) { | ||
return Z.of(M,Z.bimap( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
function(a) { return Tuple(a, Tuple.snd(t_)); }, | ||
function(b) { return Tuple(b, Tuple.snd(t_)); } | ||
function(b) { return Tuple(b, Tuple.snd(t_)); }, | ||
Tuple.fst(t_) | ||
)); | ||
}); | ||
}, stepFn(Tuple.fst(t))._run(Tuple.snd(t))); | ||
}, Tuple(init, s)); | ||
}); | ||
}); | ||
StateT.lift = function(ma) { | ||
return StateT(function(s) { | ||
return ma.chain(function(a) { | ||
return M.of(Tuple(a, s)); | ||
return Z.chain(ma, function(a) { | ||
return Z.of(M, Tuple(a, s)); | ||
}); | ||
}); | ||
}; | ||
StateT.get = StateT(function(s) { | ||
return M.of(Tuple(s, s)); | ||
return Z.of(M, Tuple(s, s)); | ||
}); | ||
StateT.gets = function(f) { | ||
return StateT(function(s) { | ||
return M.of(Tuple(f(s), s)); | ||
return Z.of(M, Tuple(f(s), s)); | ||
}); | ||
}; | ||
StateT.put = function(s) { | ||
return StateT(function(_) { | ||
return M.of(Tuple(void _, s)); | ||
return Z.of(M, Tuple(void _, s)); | ||
}); | ||
}; | ||
StateT.modify = function(f) { | ||
return StateT(function(s) { | ||
return M.of(Tuple(void 0, f(s))); | ||
return Z.of(M, Tuple(void 0, f(s))); | ||
}); | ||
}; | ||
|
||
patchAll([StateT, StateT.prototype]); | ||
|
||
return StateT; | ||
} | ||
|
||
|
@@ -83,4 +87,6 @@ State.prototype.run = function(s) { | |
return this._run(s).value; | ||
}; | ||
|
||
patchAll([State, State.prototype]); | ||
|
||
module.exports = State; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
var fl = require('./fl.js'); | ||
var fixedAp = function(f) { | ||
return f.ap(this); | ||
}; | ||
|
||
var patch = function(obj){ | ||
return Object.keys(fl).forEach(function(key) { | ||
if (typeof obj[key] === 'function') { | ||
if (key === 'ap') { | ||
obj[fl[key]] = fixedAp; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't feel right to me. What would be the consequences of removing this exception? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removing this means we should revert There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change the way the existing |
||
} else { | ||
obj[fl[key]] = obj[key]; | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
var patchAll = function(objs){ | ||
return objs.forEach(patch); | ||
}; | ||
|
||
module.exports = patchAll; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module.exports = { | ||
equals: 'fantasy-land/equals', | ||
concat: 'fantasy-land/concat', | ||
empty: 'fantasy-land/empty', | ||
map: 'fantasy-land/map', | ||
ap: 'fantasy-land/ap', | ||
of: 'fantasy-land/of', | ||
reduce: 'fantasy-land/reduce', | ||
traverse: 'fantasy-land/traverse', | ||
chain: 'fantasy-land/chain', | ||
chainRec: 'fantasy-land/chainRec', | ||
extend: 'fantasy-land/extend', | ||
extract: 'fantasy-land/extract', | ||
bimap: 'fantasy-land/bimap', | ||
promap: 'fantasy-land/promap', | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just published v0.2.0. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
congrats