管道,组成和柯里 [英] Piping, Composition, and Currying

查看:87
本文介绍了管道,组成和柯里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我看来,所有这些都是相关的。有什么区别?

解决方案


  • 管道用于执行一系列操作有些价值(就像Unix中的管道)。每个函数的输入都是前一个函数的输出。显然,这需要每个函数都采用一个参数。

  • c $ c>>> )是类似的,因为它依次调用两个函数(即,第一个的输出是第二个的输入),但它返回一个函数,而不是立即调用通过将1到 N -1参数应用于 N -1的函数,Currying创建一个新函数。 / em> args


因此,构图和咖喱用于创建函数,而管道用于调用。组合和咖啡因在创建新功能方面有所不同(通过应用参数和链接)。

It seems to me that all of these are related. What is the difference?

解决方案

  • Piping is used to perform a sequence of operations on some value (just like piping in Unix). The input to each function is the output of the previous function. Obviously this requires each function take a single arg.

  • Composition (<< / >>) is similar in that it calls two functions in sequence (i.e., the output of the first is the input to the second) but it returns a function instead of immediately invoking the sequence.

  • Currying creates a new function by applying 1 to N-1 args to a function of N args

So, composition and currying are used to create functions whereas piping is used for invocation. Composition and currying differ in the way they create new functions (by applying args vs chaining).

这篇关于管道,组成和柯里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆