函数式编程里面的基本工具函数实现

栏目: 编程语言 · 发布时间: 7年前

内容简介:本文由taoweng 创作,采用本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名最后编辑时间为: Jan 9, 2019 at 01:15 pm

compose 实现

function compose(...args) {
  return (result) => {
    return args.reduceRight((result, fn) => {
      return fn(result)
    }, result)
  }
}

pipe 实现

function compose(...args) {
  return (result) => {
    return args.reduce((result, fn) => {
      return fn(result)
    }, result)
  }
}

柯里化实现

function currying(fn, ...args) {
    if (args.length >= fn.length) {
        return fn(...args)
    }
    return function (...args2) {
        return currying(fn, ...args, ...args2)
    }
}

部分应用实现

function partial(fn, ...args) {
    return (..._arg) => {
        return fn(...args, ..._arg);
    }
}

本文由taoweng 创作,采用 知识共享署名4.0 国际许可协议进行许可

本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名

最后编辑时间为: Jan 9, 2019 at 01:15 pm


以上所述就是小编给大家介绍的《函数式编程里面的基本工具函数实现》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Python for Everyone

Python for Everyone

Cay S. Horstmann、Rance D. Necaise / John Wiley & Sons / 2013-4-26 / GBP 181.99

Cay Horstmann's" Python for Everyone "provides readers with step-by-step guidance, a feature that is immensely helpful for building confidence and providing an outline for the task at hand. "Problem S......一起来看看 《Python for Everyone》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具