Let's say I have a method that applies multiple functions to a value.
Example usage:
String value = "a string with numb3r5";
Function<String, List<String>> fn1 = ...
Function<List<String>, String> fn2 = ...
Function<String, List<Integer>> fn3 = ...
InputConverter<String> converter = new InputConverter<>(value);
List<Integer> ints = converter.convertBy(fn1, fn2, fn3);
Is it possible to make it apply multiple functions with various inputs and return values?
I've tried using wildcards, but this doesn't work.
public class InputConverter<T> {
private final T src;
public InputConverter(T src) {
this.src = src;
}
public <R> R convertBy(Function<?, ?>... functions) {
R value = (R) src;
for (Function<?, ?> function : functions)
value = (R) function.apply(value);
^^^^^
return value;
}
}