-
-
Save pditommaso/10269533 to your computer and use it in GitHub Desktop.
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
@Grab('org.slf4j:slf4j-api:1.6.1') | |
@Grab('ch.qos.logback:logback-classic:0.9.28') | |
import org.slf4j.* | |
import groovy.transform.* | |
trait Loggable { | |
@Memoized getLog() { | |
LoggerFactory.getLogger( this.getClass() ) | |
} | |
} | |
class Test implements Loggable { | |
def foo() { | |
log.debug( 'Woo. In foo' ) | |
} | |
} | |
class Test2 implements Loggable { | |
def bar() { | |
log.info( 'Ha. In bar' ) | |
} | |
} | |
new Test().foo() | |
new Test2().bar() |
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
import groovy.transform.* | |
@CompileStatic | |
trait IgnoredRemovable { | |
void remove() {} | |
} | |
@CompileStatic | |
trait Endless { | |
boolean hasNext() { true } | |
} | |
@CompileStatic | |
trait EndlessIterator<T> implements IgnoredRemovable, Endless, Iterator<T> { | |
T value | |
T next() { value } | |
} | |
@CompileStatic | |
class LoadsOfOnes implements EndlessIterator<Integer> { | |
LoadsOfOnes() { | |
value = 1 | |
} | |
} | |
assert new LoadsOfOnes().take( 5 ).collect() == [ 1, 1, 1, 1, 1 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment