zoukankan      html  css  js  c++  java
  • 组合函数, compose&pipe

     
     

      const afn = function(a) {
        return a*2 
        
      }
      const bfn = function(b) {
        return b+3
      }
     
     
      const pipe = function(...fns) {
        return function(val) {
          return fns.reduce((total, fn) => {
            return fn(total)
          }, val)
        }
      }
     
      const compose = function(...fns) {
        return function(val) {
          return fns.reverse().reduce((total, fn) => {
            return fn(total)
          }, val)
        }
      }
      const myFn = pipe(bfn,afn)
      const myFnCompose = pipe(bfn,afn)
      console.log(myFn(2))// 10
      console.log(myFnCompose(2))//  7
     
    偶数
     
     
  • 相关阅读:
    然乌湖
    邦达 八宿
    芒康
    巴塘
    禾尼乡 所波大叔
    世界高城 理塘
    相克宗 藏民家
    骑行川藏--新都桥&塔公草原
    d 3
    D2
  • 原文地址:https://www.cnblogs.com/soonK/p/14563595.html
Copyright © 2011-2022 走看看