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 is suppose to take in another Function which provides another FunctionCompose as an output. The code is suppose to work when
FunctionCompose of type <String, Integer> flatMap with (Integer -> FunctionCompose<Integer, Integer>)
Thanks in advance
New contributor
SendHelp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.