Closed gm2211 closed 4 years ago
there are a lot of formatting changes that clutters up the pr
My IDE automatically strips out trailing whitespaces - but I can revert those changes
@amaembo I can't really say what belongs to StreamEx
and what doesn't, but what I know is that Java unfortunately does not have dynamic dispatch based on method signature, nor pattern matching and if you do not control a certain data type, you can't really use the visitor pattern (unless you create your own mirrored copy of the type and convert first), in which case the pattern proposed in this PR seemed reasonable.
I'm sorry but I finally decided to decline this. Essentially all the suggested enhancements could be trivially implemented with existing map
operation. The proposed mapIsInstance
will be superseded in future Java versions with switch expression (already released in Java 14)+type matching (hopefully will be here a few years later). Even now it's possible to write it as a sequence of plain old if
statements. Creating a separate API method for every possible conditional chain inside map
lambda is out of the scope of StreamEx.
@amaembo I completely agree - I should have closed this PR a while ago
This can be useful in a few instances, but especially when processing sub-classes of some type which one does not control (and therefore the visitor pattern cannot be used).
instead of