Lodash中的FP模块

  • lodash的fp模块提供了实用的对函数式编程友好的方法
  • 提供了不可变auto-curried iteratee-first data-last的方法
//lodash模块
const _=repuire('lodash');

_.map(['a,b,c'],_.toUpper);
//=>['A','B','C']
_.map(['a,b,c'])
//=>['a','b','c']

_.split("Hello World"," ");

//lodash/fp模块
const fp=require('lodash/fp');

fp.map(fp.toUpper,['a','b','c']);
fp.map(fp.toUpper)(['a','b','c']);

fp.split('','Hello World');
fp.split('')("Hello World");
//lodash的fp模块
const fp=require('lodash/fp');

const f=fp.flowRight(fp.join('-'),fp.map(fp.toLower),fp.split(' '));
console.log('NEVER SAY');

map方法的区别

const _=require('lodash');
//数据优先,函数之后
console.log(_.map(['23','8','10'],parseInt);
);
//paseInt('23',0,array)
//paseInt('8',1,array)
//paseInt('10',2,array)
const fp=require('lodash/fp');

console.log(fp.map(parseInt,['23','8','10']));
posted @ 2022-01-25 15:33  flyall  阅读(235)  评论(0)    收藏  举报