summaryrefslogtreecommitdiffhomepage
path: root/groovy.html.markdown
diff options
context:
space:
mode:
authorSuzane Sant Ana <tetestonaldo@gmail.com>2017-12-31 14:27:06 -0200
committerGitHub <noreply@github.com>2017-12-31 14:27:06 -0200
commit42f9329bb3a028d374d6397991ac48b44064741e (patch)
tree1e75e2b3e122aeb863e3ffa037f6f64c4027fbf8 /groovy.html.markdown
parente6b77595f2669d66ac7be43c6e6083cbff80a9a7 (diff)
parent70a36c9bd970b928adde06afb2bd69f6ba8e5d5c (diff)
Merge pull request #1 from adambard/master
update
Diffstat (limited to 'groovy.html.markdown')
-rw-r--r--groovy.html.markdown31
1 files changed, 19 insertions, 12 deletions
diff --git a/groovy.html.markdown b/groovy.html.markdown
index 8fb1b346..efbb2b32 100644
--- a/groovy.html.markdown
+++ b/groovy.html.markdown
@@ -6,15 +6,15 @@ contributors:
filename: learngroovy.groovy
---
-Groovy - A dynamic language for the Java platform [Read more here.](http://groovy.codehaus.org)
+Groovy - A dynamic language for the Java platform [Read more here.](http://www.groovy-lang.org/)
```groovy
/*
Set yourself up:
- 1) Install GVM - http://gvmtool.net/
- 2) Install Groovy: gvm install groovy
+ 1) Install SDKMAN - http://sdkman.io/
+ 2) Install Groovy: sdk install groovy
3) Start the groovy console by typing: groovyConsole
*/
@@ -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
@@ -222,16 +230,18 @@ for (i in array) {
//Iterate over a map
def map = ['name':'Roberto', 'framework':'Grails', 'language':'Groovy']
-x = 0
+x = ""
for ( e in map ) {
x += e.value
+ x += " "
}
+assert x.equals("Roberto Grails Groovy ")
/*
Operators
Operator Overloading for a list of the common operators that Groovy supports:
- http://groovy.codehaus.org/Operator+Overloading
+ http://www.groovy-lang.org/operators.html#Operator-Overloading
Helpful groovy operators
*/
@@ -249,7 +259,7 @@ def username = user?.username
A Groovy Closure is like a "code block" or a method pointer. It is a piece of
code that is defined and then executed at a later point.
- More info at: http://groovy.codehaus.org/Closures+-+Formal+Definition
+ More info at: http://www.groovy-lang.org/closures.html
*/
//Example:
def clos = { println "Hello World!" }
@@ -272,7 +282,7 @@ def clos = { print it }
clos( "hi" )
/*
- Groovy can memorize closure results [1][2][3]
+ Groovy can memoize closure results [1][2][3]
*/
def cl = {a, b ->
sleep(3000) // simulate some time consuming processing
@@ -405,11 +415,11 @@ assert sum(2,5) == 7
## Further resources
-[Groovy documentation](http://groovy.codehaus.org/Documentation)
+[Groovy documentation](http://www.groovy-lang.org/documentation.html)
[Groovy web console](http://groovyconsole.appspot.com/)
-Join a [Groovy user group](http://groovy.codehaus.org/User+Groups)
+Join a [Groovy user group](http://www.groovy-lang.org/usergroups.html)
## Books
@@ -422,6 +432,3 @@ Join a [Groovy user group](http://groovy.codehaus.org/User+Groups)
[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
-
-
-