18.1. Standard augmentations (gololang.StandardAugmentations)

This Golo module provides standard augmentations for various classes of the Java standard classes and Golo types. It does not have to be imported explicitely.

Here are a few examples.

Java collections can be have functional methods:

println(list[1, 2, 3, 4]: filter(|n| -> (n % 2) == 0))
println(list[1, 2, 3]: map(|n| -> n * 10))

Insert a map entry only if the key is not present, and get a default value if an entry is missing:

map: putIfAbsent(key, -> expensiveOperation())
map: getOrElse(key, "n/a")

Repeat an operation many times:

3: times(-> println("Hey!")
3: times(|i| -> println(i))

Function references are method handles, and there are augmentations for them:

# Composition
let f = |x| -> x + 1
let g = |y| -> y * 10
let h = f: andThen(g)

# Partial application
let adder = |x, y| -> x + y
let add2 = adder: bindAt(1, 2)    # binds 'y'
println(add2(1))