相关疑难解决方法(0)

在 fp-ts 中链接一些异步任务,保留每个任务的结果

在 fp-ts 中,我试图将一些可能失败的异步任务链接在一起,TaskEither但我需要稍后在链中使用中间任务的结果。

在这个例子中:

const getFoo = (a: string): Promise<Foo> => {};
const getBar = (foo: Foo): Promise<Bar> => {};
const mkFooBar = (foo: Foo, bar: Bar): Promise<FooBar> => {};

const async main1: Promise<FooBar> => {
  const a = "a";
  const foo = await getFoo(a);
  const bar = await getBar(foo);
  const fooBar = await mkFooBar(foo, bar);

  return Promise.resolve(fooBar);
};

const main2: Promise<FooBar> => {
  const a = "a";

  return pipe(
    TE.tryCatch(() => getFoo(a), e => e),
    TE.chain(foo => …
Run Code Online (Sandbox Code Playgroud)

typescript fp-ts

10
推荐指数
1
解决办法
1574
查看次数

标签 统计

fp-ts ×1

typescript ×1