summaryrefslogtreecommitdiffhomepage
path: root/groovy.html.markdown
diff options
context:
space:
mode:
authorLuis Custodio <luis.custodio@gmail.com>2015-10-17 13:11:25 +0200
committerLuis Custodio <luis.custodio@gmail.com>2015-10-17 13:11:25 +0200
commitf5873b08901bfaec3fb46518258ff9e886fd04c4 (patch)
tree62886b71c7226f0c6c4f979d61ff96c839a641a9 /groovy.html.markdown
parentc9348e5a82b639093f8f3eee955ffdf6fb99b5d8 (diff)
parent0e6d9f6fe9aeffc64c3adad3e4a0ee1cc0d1dd88 (diff)
Merge branch 'master' of github.com:adambard/learnxinyminutes-docs
Diffstat (limited to 'groovy.html.markdown')
-rw-r--r--groovy.html.markdown13
1 files changed, 9 insertions, 4 deletions
diff --git a/groovy.html.markdown b/groovy.html.markdown
index 519f36ce..492c1ba2 100644
--- a/groovy.html.markdown
+++ b/groovy.html.markdown
@@ -99,7 +99,7 @@ technologies.sort()
// To sort without mutating original, you can do:
sortedTechnologies = technologies.sort( false )
-/*** Manipulating Lists ***/
+/*** Manipulating Lists ***/e
//Replace all elements in the list
Collections.replaceAll(technologies, 'Gradle', 'gradle')
@@ -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 it:
+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
-
-
-