Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-4144

Closures should have rcurry and ncurry as well as curry

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7.1
    • 1.7.2, 1.8-beta-1
    • None
    • None

    Description

      Sometimes you don't want to curry from the left hand side. You can always fake it by rewriting a reversed method or Closure manually but most functional languages support currying from the right or an arbitrary index.

      An rcurry method allows examples like this:

      def divide = { a, b -> a / b }
      def halver = divide.rcurry(2)
      assert halver(8) == 4
      

      An ncurry method would allow, as an example, to curry the middle parameter of a three argument method, e.g.:

      // curry middle param of this utility method:
      // Collections#binarySearch(List list, Object key, Comparator c)
      def catSearcher = Collections.&binarySearch.ncurry(1, "cat")
      def result = catSearcher(myList, myComparator)
      

      Attachments

        Activity

          People

            paulk Paul King
            paulk Paul King
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: