javascript - 如何在 JS 中演示简单的无点样式
问题描述
Point-Free 风格或默认编程在 wikipedia 中使用 Python 进行了解释。
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]);
推荐阅读
- java - 仅具有队列通信和性能测试的春季应用程序
- oracle - PL/SQL: For 循环选择列表
- visual-studio - Visual Studio 无法识别项目中的命名空间
- azure - 使用 strictfilter 调用 QnA api 时出现 Http 500 错误
- plsql - 如何将变量从存储过程传递到另一个存储过程
- c# - 有时渲染,有时不渲染的图像
- javascript - clearvalidators 不能在 Angular 6 表单控件中工作
- python - 将数据集传递给 keras 时如何在数据集上初始化迭代器
- recursion - 在 C# 中创建递归方法
- mysql - GROUP_CONCAT 和连接,如何也包括不匹配的行