Hamburg Haskell Meetup
Aug 24, 2016
function duplicate(n) {
return [n, n];
}
_.flatMap([1, 2], duplicate);
// ➜ [1, 1, 2, 2]
JavaScript: lodash for collections
Java: Optional
Optional<Int> foo = Optional.of(3);
// Optional<Int> foo = Optional.empty();
Optional<Int> bar = foo.flatMap(n -> {
if (even(n)) {
return Optional.of(n + 1);
} else {
return Optional.empty();
}
});