/vavr-groovy

Groovy extensions for vavr - http://vavr.io

Primary LanguageJavaApache License 2.0Apache-2.0

Maven Build Status codecov

This library provides groovy extension modules which allows to use vavr functional data structures with groovy closures without a pain.

For example,

def option = Option.when(true) {
  "True"
}

// when no extension provided closure argument will not coerce to supplier 
// because of Option has method signature Option#when(T object)
assert option.get() instanceof Closure

// as a workaround you can cast closure to supplier directly
Option.when(true, { "True" } as Supplier)

// or when extension provided this example just works as how it should
assert option.get() == "True"

More examples

// tuple multiple assignment
def (a, b, c) = new Tuple3(1, "A", true)

// infinite streams
assert Stream.iterate(1) {
  ++ it
}.take(3) == Stream.of(1, 2, 3)

// pattern matching
import static com.github.timic.vavr.groovy.API.*

assert Match(3).of(
    Case(1) {
        "One"
    },
    Case(3) {
        "Three"
    }) == "Three"

You can find more example in tests files.

Download

Download via gradle:

repositories {
    jcenter()
}

dependencies {
    compile "com.github.timic:vavr-groovy:0.3.0"
}