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
}
);