小编ano*_*ale的帖子

将任一<E,A> 数组转换为任一<E,A[]>(Scalaz 中的序列函数)

我仍在学习和使用 fp-ts 并且无法弄清楚这一点。

我有一个数组,Either<any, number>[]我想得到一个Either<any, number[]>.

我已经查看Apply.sequenceT了示例 sequenceToOption,它看起来很接近。

import { NumberFromString } from 'io-ts-types/lib/NumberFromString'
import { Either } from 'fp-ts/lib/Either'

const a:Either<any,number>[] = ['1','2','3'].map(NumberFromString.decode)

console.log(a)
// [ { _tag: 'Right', right: 1 },
//   { _tag: 'Right', right: 2 },
//   { _tag: 'Right', right: 3 } ]
Run Code Online (Sandbox Code Playgroud)

我想要一个错误或数字数组。

functional-programming fp-ts

6
推荐指数
1
解决办法
625
查看次数

如何在 FP-TS 中链接依赖的 TaskEither 操作

我是 FP-TS 的新手,仍然不太明白如何使用TaskEither. 我正在尝试异步读取文件,然后使用 yaml-parse-promise 解析结果字符串。

==编辑==

我使用文件的完整内容更新了代码以提供更多上下文,并应用了 MnZrK 提供的一些建议。抱歉,我对 FP-TS 还很陌生,并且仍在努力使类型匹配。

现在我的错误在于该行map(printConfig)

Argument of type '<E>(fa: TaskEither<E, AppConfig>) => TaskEither<E, AppConfig>' is not assignable to parameter of type '(a: TaskEither<unknown, AppConfig>) => Either<unknown, Task<any>>'.
  Type 'TaskEither<unknown, AppConfig>' is not assignable to type 'Either<unknown, Task<any>>'.
    Type 'TaskEither<unknown, AppConfig>' is missing the following properties from type 'Right<Task<any>>': _tag, rightts(2345)
Run Code Online (Sandbox Code Playgroud)

[我通过使用 TaskEither 中的 getOrElse 解决了这个问题,而不是来自 Either 库]

==编辑结束==

我已使用 IOEither 成功执行此操作,作为此项目的同步操作: https: //github.com/anotherhale/fp-ts_sync-example

我还查看了这里的示例代码: https ://gcanti.github.io/fp-ts/recipes/async.html

完整代码在这里: …

fp-ts

5
推荐指数
1
解决办法
6628
查看次数

标签 统计

fp-ts ×2

functional-programming ×1