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
def factorial ={ n -> | |
if (n == 0) 1 | |
else n * factorial(n - 1) | |
} | |
factorial(4) |
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
def factorial ={ n, accumulator=1 -> | |
if (n == 1) accumulator | |
else factorial(n-1, n*accumulator) | |
} | |
factorial(4) |
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
def factorial ={ n, accumulator=1 -> | |
if (n == 1) accumulator | |
else factorial.trampoline(n-1, n*accumulator) | |
}.trampoline() | |
factorial(4) |
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
def percentage = { percentage, x -> | |
x/100 * percentage | |
} |
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
def tenPercent = percentage.curry(10) |
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
def list = ['groovy', 'functional'] | |
//This mutates the original list | |
list.add('programming') | |
//This creates a new list leaving the original unchanged | |
def newList = list.plus(2, 'programming') |
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
class UnwelcomeVisitorIterator { | |
static public traverse( data, visitor ){ | |
if ( data instanceof Map ){ | |
data.each{ entrySet -> | |
entrySet.value = visitor.visitMap( entrySet.key, entrySet.value ) | |
entrySet.value = traverse( entrySet.value, visitor ) | |
} | |
} else if ( data instanceof Collection ){ | |
def processedList = [] |
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
//This code iterates a nested Map/List structure and converts any Date objects it finds into | |
// String equivalents. | |
//def data = [:] - data is some complex nested Map/List data structure | |
UnwelcomeVisitor.traverse( data, [ | |
visitMap: { key, value -> | |
if ( value instanceof Date ) value = value.toString() | |
value | |
}, | |
visitList: { entry -> | |
if ( entry instanceof Date ) entry = entry.toString() |
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
Entity people = schema.addEntity("People"); | |
people.addIdProperty(); | |
people.addStringProperty("name").notNull(); | |
people.addStringProperty("emailAddress").notNull(); | |
/* | |
* The entity for an email | |
*/ | |
Entity email = schema.addEntity("Email"); | |
email.addIdProperty().getProperty(); |
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
<plugin> | |
<groupId>ro.isdc.wro4j</groupId> | |
<artifactId>wro4j-maven-plugin</artifactId> | |
<version>1.4.5</version> | |
<executions> | |
<execution> | |
<phase>compile</phase> | |
<goals> | |
<goal>run</goal> | |
</goals> |