Partial application and closures

前端 未结 5 1154
独厮守ぢ
独厮守ぢ 2021-02-14 06:36

I was asked what\'s the relationship between partial function application and closures. I would say there isn\'t any, unless I\'m missing the point. Let\'s say I\'m writing in p

5条回答
  •  故里飘歌
    2021-02-14 07:23

    For me, using the partialSum that way, makes sure that you only depend on one Function to sum the numbers (MySum) and that will make debugging a lot more easier if things go wrong, because you would not have to worry about the logic of your code in two different parts of your code.

    If in the future you decide to change the logic of MySum, (say for example, make it return x+y+1) then you will not have to worry about MyPartialSum because it calls MySum

    Even if it seems stupid, having code written that way is just to simplify the process of dependencies in functions. I am sure you will notice that later in your studies.

提交回复
热议问题