Per aspera ad astra.循此苦旅,以达|

flyall

园龄:4年2个月粉丝:10关注:8

2022-01-25 15:52阅读: 69评论: 0推荐: 0

Point Free

Point Free:把数据处理的过程定义成与数据无关的合成运算,不需要用到代表数据的那个参数,只要把简单的运算步骤合成到一起,在使用这种模式之前我们需要定义一些辅助的基本运算函数。

  • 不需要指明处理的数据
  • 只需要合成运算过程
  • 需要定义一些辅助的基本运算函数
const f=fp.flowRight(fp.join('-'),fp.map(_.toLower),fp.split(' '));

案例

//非point free
//Hello Word=>hello_world
function f(word){
	return word.toLowerCase().replace(/\s+/g,'_');
}
//全转化为小写,匹配空格 替换为——
//point Free
const fp=require('lodash/fp');

const f=fp.flowRight(fp.replace(/\s+/g,'_'),fp.toLower);
console.log(f('Hello World'));
//把一个字符串中的首字母提取并转换成大写,使用.作为分隔符
const fp=require('lodash/fp');

const firstLetterToUpper=fp.flowRight(fp.join('. ',fp.map(fp.first),fp.map(toUpper),fp.split(' '));
console.log(firstLetterToUpper("world wild web"));

优化

//把一个字符串中的首字母提取并转换成大写,使用.作为分隔符
const fp=require('lodash/fp');

const firstLetterToUpper=fp.flowRight(fp.join('. ',fp.map(fp.flowRight(fp.first,fp.toUpper)),fp.split(' '));
console.log(firstLetterToUpper("world wild web"));

本文作者:flyall

本文链接:https://www.cnblogs.com/flyall/p/15843314.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   flyall  阅读(69)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.