Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: Function Currying like Haskell in Python (gist.github.com)
3 points by gamegoblin on Feb 26, 2014 | hide | past | favorite | 1 comment


I hacked this together today after seeing something like:

  def add3(a):
      def add2(b):
          def add1(c):
              return a+b+c
          return add1
      return add2
But this requires one to do add3(1)(2)(3). I figured it was possible to transform functions more mechanically. The builtin "partial" function is a class that merely collects args in a list, so one can't incrementally apply a few more args at once like a real curry. It's more of a fancy lambda closure.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: