【发布时间】:2021-10-20 17:57:06
【问题描述】:
我将如何在下面的数组中用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']
【问题讨论】:
-
您要仅替换第一个匹配项还是全部替换?
-
@DenisFrezzato 这是为了替换第一次出现
标签: fp-ts