javascript - 如何在JS中演示简单的无点风格

标签 javascript functional-programming pointfree

维基百科中使用 Python 解释了 Point-Free 风格或默认编程。

def example(x):
  y = foo(x)
  z = bar(y)
  w = baz(z)
  return w

和..

def flow(fns):
    def reducer(v, fn):
        return fn(v)

    return functools.partial(functools.reduce, reducer, fns)

example = flow([baz, bar, foo])

如何使用 JS 以最简单易懂的概念形式演示这种效果?

最佳答案

可以很容易地转换成 JS:

 function example(x) {
  const y = foo(x);
  const z = bar(y);
  const w = baz(z);
  return w;
}

...和

function flow(fns) {
  function reducer(v, fn) {
     return fn(v);
  }

  return fns.reduce.bind(fns, reducer);
}

const example = flow([baz, bar, foo]);

关于javascript - 如何在JS中演示简单的无点风格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55395719/

相关文章:

haskell - (f .) . 是什么意思? g 在 Haskell 中的意思是?

javascript - Pointfree 在 Ramda 中通过对象中的键将数组连接到字符串

javascript - 如何检测HTML5视频是否暂停缓冲?

functional-programming - Isabelle 中的 Map 和 Mapping 有什么区别?

scala - 什么功能技术使得不必通过功能传递配置

javascript - Coffeescript 闭包和随机数数组

haskell - 点自由编程

php - 如何在 JavaScript 中显示多个结果?

javascript - 通过 AJAX 调用 API

javascript - html 和 javascript : How to store data referring to html elements