When should I use function currying in Python?

前端 未结 2 598
野性不改
野性不改 2021-02-05 16:55

When should I write my functions in curried form? does not match my thought, need to correct myself.

As part of my learning link, this is what I understand from function

2条回答
  •  南旧
    南旧 (楼主)
    2021-02-05 17:33

    Currying has at-least two advantages I can think of:

    1) It keeps your code (and in turn your thinking) DRY.

    Say you are have a function like:

    def call_me(context, args):
        ...
    

    by currying you can get a specialized function for that context which can be tossed around etc. You don't have to repeat the context again.

    2) Thinking in terms of a single input function is much easier than n arguments; this can be debatable at times though.

    See also: What is the difference between currying and partial application?

提交回复
热议问题