Day25: pipe

昨天我们使用 function 的 compose,
是从右至左执行,如果我们想由左至右执行,
那我们可以用 pipe, pipe 是管线的概念,
也就是依序执行 function 从第一个参数开始。

引用:https://betterprogramming.pub/compose-and-pipe-in-javascript-medium-d1e1b2b21f83?gi=d6f92bc693a9

我们先实作一个 pipe function

const pipe = (...fns) => (x) => fns.reduce((v, f) => f(v), x);

然後把昨天我们实作 compose 的 function 放进来

const toLowcase = (x)=>{
    console.log('lowCase', x.toLowerCase());
    return x.toLowerCase();
}

const withExclamationMark = (x)=>{
    console.log('!!!',x+'!!!' );
    return x+'!!!';
}

const handleString = pipe(toLowcase,withExclamationMark);
handleString('Hello')//  // 可以看到我们可以得到 hello!!! 但是会由左至右执行 function

https://betterprogramming.pub/compose-and-pipe-in-javascript-medium-d1e1b2b21f83


<<:  Day-25 说明一下 Rails 的 MVC 架构是什麽?优点是?

>>:  30-25 之 DDD 战略设计 1 - 战略设计的目的

android studio 30天学习笔记-day 6-介绍retrofit(二)

今天要来了解上一篇的各个步骤 1.创建资料类别 有个快速生成data class的插件,可以从Fil...

Day13-Async && Await

前言 虽说ES6推出了promise解决了callback hell的问题,但人总是不容易满足。 於...

[Slack] 利用 Incoming Webhooks 发送讯息至指定频道(channel)

关於Incoming Webhooks Slack是现在蛮流行的办公用通讯软件,其中有许多appli...

【day1】豚花돈꽃韩式料理三访

在近三个月的防疫禁止内用期间 最想念的食物之一就是韩式烤肉了 (不用自己动手烤的那一种) 这家豚花돈...

创建App一关於本App

创建App一关於本App(TeenMate) 为何选择在关於TeenMate的这一项功能作一天日记,...