Lodash中的FP模块
- 我们在使用函数组合解决问题的时候,会使用到lodash中提供的一些方法,但如果这些方法有多个参数的时候,我们需要对这些方法进行柯里化的处理,我们需要重新去包装这些方法,稍微有些麻烦,接下来我们来介绍lodash中的fp模块
- lodash/fp
- lodash 的 fp 模块提供了实用的对函数式编程友好的方法
- 提供了不可变 auto-curried、iteratee-first、data-last
// lodash 模块 --- 数据在前,方法在后
const _ = require('lodash')
console.log(_.map(['a', 'b', 'c'], _.toUpper))
// => [ 'A', 'B', 'C' ]
console.log(_.map(['a', 'b', 'c']))
// => [ 'a', 'b', 'c' ]
console.log(_.split('Hello World', ' '))
// => [ 'Hello', 'World' ]
// lodash/fp 模块 --- 方法在前,数据在后
const fp = require('lodash/fp')
console.log(fp.map(fp.toUpper, ['a', 'b', 'c']))
console.log(fp.map(fp.toUpper