Last active
July 11, 2016 17:22
-
-
Save fmamud/1cb9eab4fc4ffb102c419867e630a0b9 to your computer and use it in GitHub Desktop.
TDC São Paulo - Palestra: Groovy como você nunca viu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tdc.groovy.awesome | |
import groovy.transform.Immutable | |
import groovy.transform.ToString | |
// @TypeChecked | |
// @CompileStatic | |
@ToString | |
@Immutable | |
class Person { | |
String name | |
Integer id | |
} | |
def p = new Person(id: 1, name: 'Groovy') | |
p.id = 12 // exception |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tdc.groovy.awesome; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
class Boilerplate { | |
public static void main(String[] args) { | |
def names = ['Homer', 'Marge', 'Bart', 'Lisa'] | |
println names | |
def b = new Boilerplate(); | |
def shortNames = names.findAll { name -> name.size() <= 4 } | |
def shortNamesStream = names | |
.stream() | |
.filter {name -> name.length() <= 4} | |
.collect(Collectors.toList()) | |
println shortNames | |
println shortNamesStream | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tdc.groovy.awesome | |
import groovy.json.JsonBuilder | |
import groovy.xml.MarkupBuilder | |
// MarkupBuilder | |
// JSON | |
def json = new JsonBuilder() | |
json.eventos { | |
evento { | |
name 'TDC 2016' | |
palestra 'Groovy' | |
} | |
} | |
println json | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tdc.groovy.awesome | |
import groovy.transform.CompileStatic | |
import groovy.transform.TypeChecked | |
// Operator overloading | |
// Closure Delegate (EmailSender) @DelegatesTo | |
// Category | |
class EmailSender { | |
def from(String from) { println "From $from"} | |
def to(String ...to) { println "To: ${to.join(',')}" } | |
def message(String msg) { println "Message: ${msg}"} | |
} | |
def email(@DelegatesTo(EmailSender) Closure cls) { | |
cls.delegate = new EmailSender() | |
cls() | |
} | |
@TypeChecked | |
@CompileStatic | |
def enviaEmail() { | |
email { | |
from '[email protected]' | |
to '[email protected]' | |
message 'Fala ai john!! Blza?!!' | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tdc.groovy.awesome | |
println 'http://www.google.com.br'.toURL().text | |
println 'ls -l'.execute().text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tdc.groovy.awesome | |
//Optional (Typing, Semicolons, Parentheses, public & return keyword); | |
def hello(String saudacao) { | |
"Bem vindos ao " + saudacao | |
} | |
def nomes = ['Dooms', 'Tincas', 'John'] | |
println nomes.class | |
hello "TDC 2016" | |
def map = [nome: 'Dooms', lang:'Groovy'] | |
map.each { e -> | |
println "${e.key} ${e.value}" | |
} | |
(1..10).each { n -> | |
println n | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment