gpt4 book ai didi

javascript - 是否有 ramda 函数可以帮助您将日志记录添加到管道/组合中?

转载 作者:行者123 更新时间:2023-11-29 10:28:36 24 4
gpt4 key购买 nike

我想将日志记录添加到像这样的组合函数链中

const f = R.compose(
transformation2,
doAlso(x => console.log(`id: ${x.id}`)),
transformation1
)

这将首先应用 transformation1,然后在将结果值传递给 transformation2 之前记录结果值的 id。

实现起来会很容易

doAlso = f => x => {
f(x)
return x
}

但它似乎应该是一个很常见的模式。这个概念叫什么?像 ramda 这样的 FP 库中是否存在类似的功能?

最佳答案

这个函数叫做tap在 Ramda 中。

关于javascript - 是否有 ramda 函数可以帮助您将日志记录添加到管道/组合中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52121641/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com