summaryrefslogtreecommitdiffhomepage
path: root/groovy.html.markdown
diff options
context:
space:
mode:
authorRibeiro <geovanny.ribeiro@gmail.com>2015-10-06 15:09:29 -0300
committerRibeiro <geovanny.ribeiro@gmail.com>2015-10-06 15:09:29 -0300
commitd810a71b76892aef7404293d6fe4bec3b9dbb31e (patch)
tree0a4518ad1f95cd664ea68d96df5467a01a8a3969 /groovy.html.markdown
parenta8621d1aad09b4ddedb14710d7ac870e1eecbe67 (diff)
Added The Elvis Operator to Groovy docs
Diffstat (limited to 'groovy.html.markdown')
-rw-r--r--groovy.html.markdown11
1 files changed, 8 insertions, 3 deletions
diff --git a/groovy.html.markdown b/groovy.html.markdown
index 519f36ce..c80fcc89 100644
--- a/groovy.html.markdown
+++ b/groovy.html.markdown
@@ -200,6 +200,14 @@ def y = 10
def x = (y > 1) ? "worked" : "failed"
assert x == "worked"
+//Groovy supports 'The Elvis Operator' too!
+//Instead of using the ternary operator:
+
+displayName = user.name ? user.name : 'Anonymous'
+
+//We can write like this:
+displayName = user.name ?: 'Anonymous'
+
//For loop
//Iterate over a range
def x = 0
@@ -422,6 +430,3 @@ Join a [Groovy user group](http://www.groovy-lang.org/usergroups.html)
[1] http://roshandawrani.wordpress.com/2010/10/18/groovy-new-feature-closures-can-now-memorize-their-results/
[2] http://www.solutionsiq.com/resources/agileiq-blog/bid/72880/Programming-with-Groovy-Trampoline-and-Memoize
[3] http://mrhaki.blogspot.mx/2011/05/groovy-goodness-cache-closure-results.html
-
-
-