Piping, Composition, and Currying

后端 未结 2 407
無奈伤痛
無奈伤痛 2021-02-02 13:21

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

2条回答
  •  梦如初夏
    2021-02-02 13:56

    • 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).

提交回复
热议问题