Details

    • Type: New Feature New Feature
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: 3.0
    • Component/s: groovy-jdk
    • Labels:
      None

      Description

      Hi.

      Groovy's Closure have a name of method 'curry'.
      But this is not work for a real currying, it work as a partial function application.
      So, I wrote method of 'Real currying'.

      Referenced http://en.wikipedia.org/wiki/Currying

      Closure add = {a, b, c -> a + b + c } // Closure of adding 3 arguments.
      
      assert add(1, 2, 3) == realCurry(add)(1)(2)(3)
      assert 6 == add(1, 2, 3)
      def curriedAdd = realCurry(add)
      def curriedAdd_1 = curriedAdd(1)
      def curriedAdd_1_2 = curriedAdd_1(2)
      def addResult = curriedAdd_1_2(3)
      assert 6 == addResult
      
      def realCurry(Closure clos) {
        if (clos.maximumNumberOfParameters >= 1) {
          return { x ->
            def cc = clos.curry(x)
            if (cc.maximumNumberOfParameters) realCurry(cc)
            else cc()
          }
        } else {
          return clos
        }
      }
      

      (It's also published on gist https://gist.github.com/1193548)

      I hope this will be adopted to Groovy core.

      Thank you.

        Issue Links

          Activity

          Kentaro Yoshida created issue -
          Jochen Theodorou made changes -
          Field Original Value New Value
          Fix Version/s 2.0 [ 13489 ]
          Component/s syntax [ 11337 ]
          Priority Minor [ 4 ] Major [ 3 ]
          Component/s groovy-jdk [ 10750 ]
          Issue Type Wish [ 5 ] Bug [ 1 ]
          Pascal Schumacher made changes -
          Link This issue is duplicated by GROOVY-6281 [ GROOVY-6281 ]
          Pascal Schumacher made changes -
          Issue Type Bug [ 1 ] New Feature [ 2 ]
          Mark Thomas made changes -
          Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
          Mark Thomas made changes -
          Workflow jira [ 12733924 ] Default workflow, editable Closed status [ 12745744 ]
          Mark Thomas made changes -
          Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
          Mark Thomas made changes -
          Workflow jira [ 12972639 ] Default workflow, editable Closed status [ 12980479 ]

            People

            • Assignee:
              Unassigned
              Reporter:
              Kentaro Yoshida
            • Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

              • Created:
                Updated:

                Development