If I have a Task
that has an Either err b
for the right (success) value, how can I combine / merge / transform them so the success value is available directly in the .fork()
, not wrapped in an Either
?
const Task = require('data.task'); // folktale
const Either = require('data.either');
// eitherYayNay :: Bool → Either String String
const eitherYayNay = bool =>
bool ? Either.Right('yay') : Either.Left('nay');
// theTask :: Bool → Task Either a b
const theTask = yn =>
new Task((reject, resolve) => {
resolve(eitherYayNay(yn));
// reject();
});
// niceTask :: Bool → Task a b
// ???
// the desired result...
niceTask(something).fork(
err => {
// err could be the left value of the Task, or of the Either
},
val => {
console.log(val); // a string, not an Either
}
);
This is what I would do:
See the demo:
Hope that helps.