fp-ts - 替换 fp-ts 中的数组元素
问题描述
我将如何在下面的数组中cat
替换字符串?dog
我下面的示例是标准 js 和 fp-ts 的混合,很好奇 Array 模块中是否有可以解决这个问题的东西。
const animals = ['monkey','cat','lion']
const result = pipe(
animals,
A.findIndex((animal)=> animal === 'cat'),
O.matchW(
() => animals,
(index) => //Looking for fp-ts solution here
)
)
//Expected Result: ['monkey','dog','lion']
解决方案
我会用A.updateAt
. 请注意,我还包装O.none
了条件结果,因此它们两个条件都返回Option<string[]>
O.matchW(
() => O.some(animals),
(index) => A.updateAt(index, 'dog')(animals)
)
推荐阅读
- oracle - 如何更新表并在同一个触发器中引发错误而不引发 ORA-04091 变异表错误
- mysql - First time using mysql...ImportError:
- c# - C#需要等待线程完成而不阻塞UI线程
- javascript - How can I append a string to a div by referencing an object key?
- java - 关于数组问题的问题(查找重复项)
- node.js - Your connection is not private NET::ERR_CERT_AUTHORITY_INVALID Nodejs localhost
- dart - 重新编译后文件丢失
- python - How to access widgets' properties dynamically in python + kivy
- javascript - 如何将 Html 标签插入传入的动态文本
- shell - 是否可以返回并更改您在命令提示调查表中输入的最后一个输入?