This file contains 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
Bundle groovy = Platform.getBundle("org.codehaus.groovy"); | |
final GroovyClassLoader transformLoader = new GroovyClassLoader(groovy.adapt(BundleWiring.class).getClassLoader()); | |
GroovyClassLoader loader = new GroovyClassLoader(getClass().getClassLoader()) { | |
@Override | |
protected CompilationUnit createCompilationUnit(CompilerConfiguration config, CodeSource source) { | |
return new CompilationUnit(config, source, this, transformLoader, true, null, null); | |
} | |
}; | |
Class<?> cl = loader.parseClass(new GroovyCodeSource(capellaScriptFile.getLocation().toFile(), capellaScriptFile.getCharset())); | |
InvokerHelper.runScript(cl, args); |
This file contains 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
import groovy.transform.* | |
@ToString | |
class Vehicle { | |
String brand | |
String model | |
Integer wheels | |
} | |
class Car extends Vehicle {} |
This file contains 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
import org.codehaus.groovy.control.CompilationUnit | |
import org.codehaus.groovy.control.CompilerConfiguration | |
import org.codehaus.groovy.ast.* | |
import org.codehaus.groovy.ast.expr.* | |
import org.codehaus.groovy.ast.stmt.* | |
String code = ''' | |
class PersonSpec { |
This file contains 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
UserDetails getUserDetails(String username) { | |
return UserDetails.findByUsername(username) | |
} | |
UserRole getUserRole(String username) { | |
return UserRole.findByUserName(username) | |
} | |
UserDetails getUserDetailsNoMatterWhat(String username) { |
This file contains 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
################################################ | |
# Dockerfile to run Groovy containers | |
# Based on Java 8 image | |
################################################ | |
FROM java:8u40-jdk | |
MAINTAINER Cédric Champeau | |
RUN apt-get update |
This file contains 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
import static java.lang.Integer.* | |
import static groovyfp.categories.Fn.* | |
def zero = { 0 } | |
def parse = { String c -> return { parseInt(c) } } | |
def addOne = { Integer y -> y + 1 } | |
def addToListIfValue = { Integer z -> z ? List(z) : List() } | |
// Getting every item in the list |
This file contains 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
import static groovyfp.categories.Fn.* | |
import groovyfp.categories.* | |
/* | |
a = do | |
x <- (1..3) | |
y <- ('a','b') | |
return (x,y) | |
a = mdo { |
This file contains 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
def elements = [1..4, 30..50, 'a'..'d'] | |
def iterators = elements*.iterator() | |
while(iterators*.hasNext().every()) { | |
println iterators*.next() | |
} |
This file contains 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
@Override | |
public <B, M extends Monad<B>> M bind(Function<A, M> fn) { | |
List<B> result = new ArrayList<>(); | |
for(A v : this.getTypedRef().getValue()) { | |
ListMonad<B> partialMonad = (ListMonad<B>) fn.apply(v); | |
result.addAll(partialMonad.getTypedRef().getValue()); | |
} | |
return (M) result; | |
} |
This file contains 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
interface HasUser { | |
User getUser() | |
} | |
interface HasBank { | |
Bank getBank() | |
} | |
interface Validator<T> { | |
Boolean validate(T validateable) |
NewerOlder