Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Apache Groovy
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
====Curry==== Usually called ''[[partial application]]'',<ref name=":0">[http://programmers.stackexchange.com/questions/152868/does-groovy-call-partial-application-currying "Does groovy call partial application 'currying']", 10 Aug 2013</ref> this Groovy feature allows closures' parameters to be set to a default parameter in any of their arguments, creating a new closure with the bound value. Supplying one argument to the <code>curry()</code> method will fix argument one. Supplying N arguments will fix arguments 1 .. N. <syntaxhighlight lang="groovy"> def joinTwoWordsWithSymbol = { symbol, first, second -> first + symbol + second } assert joinTwoWordsWithSymbol('#', 'Hello', 'World') == 'Hello#World' def concatWords = joinTwoWordsWithSymbol.curry(' ') assert concatWords('Hello', 'World') == 'Hello World' def prependHello = concatWords.curry('Hello') //def prependHello = joinTwoWordsWithSymbol.curry(' ', 'Hello') assert prependHello('World') == 'Hello World' </syntaxhighlight> Curry can also be used in the reverse direction (fixing the last N arguments) using <code>rcurry()</code>. <syntaxhighlight lang="groovy"> def power = { BigDecimal value, BigDecimal power -> value**power } def square = power.rcurry(2) def cube = power.rcurry(3) assert power(2, 2) == 4 assert square(4) == 16 assert cube(3) == 27 </syntaxhighlight> Groovy also supports [[lazy evaluation]],<ref>{{cite web |url=http://groovy.codehaus.org/Lazy+transformation |title=Groovy - Lazy Transformation |access-date=2012-10-07 |archive-url=https://web.archive.org/web/20121008091312/http://groovy.codehaus.org/Lazy+transformation |archive-date=2012-10-08 |url-status=dead }}</ref><ref>{{cite web|url=http://ndpar.blogspot.com.br/2011/02/lazy-lists-in-groovy.html|title=Side Notes: Lazy lists in Groovy|date=3 Feb 2011}}</ref> [[Fold (higher-order function)|reduce/fold]],<ref>{{cite web |url=http://bendoerr.me/posts/2011-06-20-groovy-inject.html |title=Groovy's Fold |date=20 Jun 2011 |access-date=12 February 2015 |archive-url=https://web.archive.org/web/20150213033355/http://bendoerr.me/posts/2011-06-20-groovy-inject.html |archive-date=13 February 2015 |url-status=dead }}</ref> [[Data structure|infinite structure]]s and [[immutability]],<ref>{{cite web |url=http://www.slideshare.net/arturoherrero/functional-programming-with-groovy |title=Functional Programming with Groovy |date=5 Nov 2011}}</ref> among others.<ref>{{cite web |url=http://groovy.codehaus.org/Functional+Programming+with+Groovy |title=Function programming in Groovy |access-date=2012-10-07 |archive-url=https://web.archive.org/web/20121008095622/http://groovy.codehaus.org/Functional+Programming+with+Groovy |archive-date=2012-10-08 |url-status=dead }}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)