4 ms·
What do you mean by: function taking a stream<B> as input and apply it all to a stream<A>
by sumy23 4y ago
What do you mean by: function taking a stream<B> as input and apply it all to a stream<A>
- t0mas88 4y agoHe means to combine them. So when you have a function A -> B and some other function B -> X, he wants to be able to make a composed function A -> X out of them. This is a common thing in many functional style programming languages.
- jiehong 4y agoYes, but in this case, it's f: Stream<A> -> Stream<B> and g: Stream<B> -> T, and compose them into h: Stream<A> -> T. Would be nice to be able to write, for example: T result = streamOfA().apply(f).apply(g);
- PaulHoule 4y agoThere is a set of ‘compose’ operators in pidove that can not only compose functions but also let you put a bifunction or supplier at the beginning of the chain or put a consumer at the end. For it to really shine I need to add more versions of the compose function with different lengths, but I am working on a code generator that will be able automatically generate those to arbitrary length.
- kjeetgill 4y agoIt's not the most convenient syntactically, as per usual in Java land, but java.utils's Function<T, R> has both a compose() and an andThen().
- sumy23 4y agoJava can do that trivially easy for the stream case because there is only one input and one output. E.g. static <A, B, X> Function<A, X> compose(Function<A, B> one, Function<B, X> two) { return (a) -> { return two.apply(one.apply(a)); } } Java sucks when there are a variable number of generic arguments, so it struggles with the composition of two functions that have a variable number of inputs. That doesn't really apply to stream processing though.