Yep that's correct. You cant get strong typing with varargs. Overloading
(yes, lazy) is how I handle it right now. I believe there's really one 2
methods that do anything significant to accomplish the goal, one that calls
a single nested function, and one that calls a single nested BiConsumer.
The
I don't think that function chaining with varargs works, except with
UnaryOperator. After all, the output type of the first must be
compatible with the input type of the second, the output type of the
second must be compatible with the input type of the third, etc.
If you want to continue
I'm not sure the "nested" example API is quite what it should be, because
the last argument is the default value, you cannot make the input functions
a vararg, which seems very limiting. I should be able to use the same API
whether I need to go 1, 2, or N functions deep. I'm saying the above
Nice.
Sounds like everyone is leaning towards "no". Would it be worth submitting
a PR to include more usage examples - which I assume could also serve as a
place to collect more feedback? Or just keep it within this thread given
the way it's leaning? (or unless that consensus changes)
Ultimately
The function() method is a great technique, it's now in Functions and
FailableFunction (git master).
I'll see later if it can be used within Lang. I know I can use it in other
projects.
Wrt an API for a vararg of functions that implements chaining internally,
I'm not so sure. I've though I
Worth adding adding function(Function)? Seems low cost to add it
FailableFunction.
Gary
On Fri, Aug 4, 2023, 2:04 PM Rob Spoor wrote:
> With just one simple utility method you can get all the chaining you want:
>
> public static Function function(Function func) {
> return func;
Appreciate the feedback. That's a great point. I missed the potential of
the andThen(...) method.
One minor thing to point out - My proposed purpose of the default value
parameter was not to substitute the final value if it is null, but to
substitute the final value if it cannot be obtained, due
With just one simple utility method you can get all the chaining you want:
public static Function function(Function func) {
return func;
}
This doesn't look very useful, but it allows you to turn a method
reference or lambda into a typed Function without needing a cast. After
Asking for comments and thoughts on a potential new feature. Already
developed in a commons-like style, but dont want to submit PR without
discussion as it may be considered out of scope or too use case specific.
Justification and details...
I've run into a scenario a few times where nested