Relative Content

Tag Archive for javaflatmap

How do I implement flatMap for an object with a Function property?

import java.util.function.Function; class FunctionCompose<T, R> { public final Function<T, R> function; public FunctionCompose(Function<T, R> function) { this.function = function; } public <U> FunctionCompose<T, U> map(Function<? super R, ? extends U> mapper) { return new FunctionCompose<>(function.andThen(mapper)); } //code flatMap public R apply(T smth) { return function.apply(smth); } } I am stuck at writing flatMap, where it […]