如果我有一个Task
具有Either err b
正确(成功)值的值,我该如何组合/合并/转换它们,以便成功值可以直接在 中使用.fork()
,而不是包含在 中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
}
);