From d810a71b76892aef7404293d6fe4bec3b9dbb31e Mon Sep 17 00:00:00 2001 From: Ribeiro Date: Tue, 6 Oct 2015 15:09:29 -0300 Subject: Added The Elvis Operator to Groovy docs --- groovy.html.markdown | 11 ++++++++--- 1 file 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 - - - -- cgit v1.2.3 From 35ba352668f67de95e0dca7c2f1a284f5fa453b2 Mon Sep 17 00:00:00 2001 From: Geovanny Ribeiro Date: Tue, 6 Oct 2015 16:49:21 -0300 Subject: Update groovy.html.markdown --- groovy.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/groovy.html.markdown b/groovy.html.markdown index c80fcc89..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') @@ -205,7 +205,7 @@ assert x == "worked" displayName = user.name ? user.name : 'Anonymous' -//We can write like this: +//We can write it: displayName = user.name ?: 'Anonymous' //For loop -- cgit v1.2.3