将附加参数传递给 lodash 的 flow() 中的函数
Pass additional parameters to functions within lodash's flow()
如果我想将 join() 的分隔符更改为默认值以外的分隔符,我该如何将其传递给此链中的特定函数?
const evens = (x) => _.filter(x, y => y % 2 === 0)
console.log(
_.flow(
evens,
_.join,
)([1, 2, 3, 4, 5, 6])
)
// expected output: ('2+4+6')
// actual output: ('2,4,6')
这个有效
const evens = (x) => _.filter(x, y => y % 2 === 0)
console.log(
_.flow(
evens,
(a) => _.join(a, '+'),
)([1, 2, 3, 4, 5, 6])
)
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>
如果我想将 join() 的分隔符更改为默认值以外的分隔符,我该如何将其传递给此链中的特定函数?
const evens = (x) => _.filter(x, y => y % 2 === 0)
console.log(
_.flow(
evens,
_.join,
)([1, 2, 3, 4, 5, 6])
)
// expected output: ('2+4+6')
// actual output: ('2,4,6')
这个有效
const evens = (x) => _.filter(x, y => y % 2 === 0)
console.log(
_.flow(
evens,
(a) => _.join(a, '+'),
)([1, 2, 3, 4, 5, 6])
)
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>