我该如何在下面的数组中用dog替换字符串cat呢?
我下面的例子是标准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']发布于 2021-08-19 15:53:30
我会使用A.updateAt。请注意,我还包装了O.none条件结果,以便这两个条件都返回Option<string[]>
O.matchW(
() => O.some(animals),
(index) => A.updateAt(index, 'dog')(animals)
)https://stackoverflow.com/questions/68840827
复制相似问题