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.* | |
//@CompileStatic | |
class Person { | |
String name | |
private List<Person> friends | |
String friendNames() { | |
friends.collect { it.name }.join(", ") | |
} |
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
JobParameters fromMap(Map<String, String> parameters) { | |
parameters.inject(new JobParametersBuilder()) { JobParametersBuilder builder, entry -> | |
builder.addParameter(entry.key, new JobParameter(entry.value)) | |
} toJobParameters() | |
} |
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
@Grab("io.reactivex:rxjava:1.0.8") | |
import rx.* | |
import static java.util.concurrent.TimeUnit.* | |
import static java.time.LocalTime.* | |
def sub = Observable.interval(1, SECONDS) | |
.doOnNext { tick-> | |
println "tick $tick at ${now()}" | |
} | |
.subscribe { tick -> |
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
package example | |
import java.time._ | |
case class Event(description: String, time: Option[ZonedDateTime]) | |
object Event { | |
def apply(description: String) = new Event(description, None) | |
def apply(description: String, time: ZonedDateTime) = new Event(description, Some(time)) | |
} |
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 com.fasterxml.jackson.annotation.JsonSubTypes.Type | |
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id | |
import com.fasterxml.jackson.annotation.{JsonSubTypes, JsonTypeInfo} | |
@JsonTypeInfo(use = Id.NAME, property = "name") | |
@JsonSubTypes(Array( | |
new Type(classOf[Vodka.type]), | |
new Type(classOf[Whiskey]) | |
)) | |
trait Spirit |
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
ctx | |
.byMethod(spec -> | |
spec | |
.get(() -> ctx.render("GET")) | |
.post(() -> ctx.render("POST")) | |
); |
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
fun diamond(c: Char): String { | |
if (c !in 'A'..'Z') throw IllegalArgumentException() | |
return ('A'..c) | |
.map(row(c)) | |
.mirrorDown() | |
.joinToString("\n") | |
} | |
private fun row(max: Char) = { next: Char -> | |
"$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
import org.jetbrains.spek.api.* | |
class InteropNullabilitySpec : Spek() { | |
init { | |
given("a java object with null state") { | |
val obj = JavaStringWrapper(null) | |
on("calling a getter that will return null") { | |
it("allows me to assign the result to a nullable type") { | |
val s: String? = obj.value | |
shouldBeNull(s) |
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.* | |
@CompileStatic | |
Map<String, ?> makeMap() { | |
def map = [string: "string"] | |
map.number = 1 | |
return map | |
} | |
def map = makeMap() |
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.jetbrains.spek.api.Spek | |
class TableSpec : Spek({ | |
describe("using a table") { | |
table { a: String, b: Int -> | |
describe("$a and $b are parameters") { | |
it("should work") { | |
assert(a is String) | |
assert(b is Int) | |
} |