-
Currently do-notation only works for Future's. Is there any way to make it work with fantasy land spec monads? e.g: const Future = require('fluture');
const RF = require('ramda-fantasy');
function getX() {
return RF.Maybe.Just(1);
}
function getY(x) {
return RF.Maybe.Just(x + 1);
}
const f = Future.do(function *() {
const x = yield getX();
const y = yield getY(x);
return x + y;
});
f.fork(console.error, console.log); This outputs error: But if we replace Is there currently any way to make it work with e.g |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
There are general implementations of do-notation out there, for example I'm not sure from your code example whether you want do-notation for Maybes specifically, or whether you want do-notation that can mix Maybes and Futures. In case of the former, one of the mentioned libraries will be exactly what you need. In case of the latter, we will need to explore alternatives, as there is no (sane) way to implement do notation to work on mixed types of Monads. This is for the same reason that you cannot do
|
Beta Was this translation helpful? Give feedback.
-
Ahh, it's all clear now. Thank you for the response! |
Beta Was this translation helpful? Give feedback.
There are general implementations of do-notation out there, for example
fantasydo
,fantasy-do
, anddo-notation
. However, due to the mutable nature of generators in JavaScript, these implementations often cause problems when used with Futures that are forked more than once.I'm not sure from your code example whether you want do-notation for Maybes specifically, or whether you want do-notation that can mix Maybes and Futures. In case of the former, one of the mentioned libraries will be exactly what you need.
In case of the latter, we will need to explore alternatives, as there …