19. 函数组合-debug
leezozz 1/27/2023 js
// 函数组合-debug 调试
// 两个参数的函数不能直接在函数组合中使用,只能是一个参数的函数
// NEVER SAY DIE ---> never-say-die
const _ = require('lodash')
// _.split(字符串,分隔符)
// 使用柯里化将其转化为一元参数
const split = _.curry((sep, str) => _.split(str, sep))
// _.toLower()
// _.join(数组,分隔符)
const join = _.curry((sep, arr) => _.join(arr, sep))
function log(val) {
console.log('val', val)
return val
}
const map = _.curry((fn, arr) => _.map(arr, fn))
const trace = _.curry((tag, v) => {
console.log(tag, v)
return v
})
// const f = _.flowRight(join('-'), log, map(_.toLower), split(' '))
const f = _.flowRight(join('-'), trace('map之后'), map(_.toLower), trace('split之后'), split(' '))
console.log('f', f('NEVER SAY DIE'))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32