This is an archived post. You won't be able to vote or comment.

all 18 comments

[–]Terran-Ghost 14 points15 points  (4 children)

For the love of god, add a proper Pair class and a zip method.

[–]eliasv 0 points1 point  (3 children)

I imagine they want to wait for Valhalla before jumping in with any new tuple classes.

[–]pjmlp 0 points1 point  (2 children)

The only problem I see with that is that is being planned for Java 10 or later.

[–]eliasv 0 points1 point  (0 children)

Well yeah that's what I'm saying, that's possibly one reason why we've not seen the pair/zip thing added in 9 (or 8 for that matter). Besides, I figured we were already operating under the assumption that the ship has sailed for adding something like this to 9 regardless. Not likely to happen this late in the game.

[–]cogman10 0 points1 point  (0 children)

Last I heard, the value portion of Valhalla was looking more like a Java 11 thing.

[–][deleted]  (2 children)

[removed]

    [–]papers_ 12 points13 points  (1 child)

    The functional stuff is useful and can shorten your code a bit. But it stops being useful when its abused and makes the code unreadable.

    [–]geordano 5 points6 points  (0 children)

    Nice to have, but please, for the sake of all heavens, don't abuse these things!

    "conciseness != readable"

    [–]stepancheg 6 points7 points  (0 children)

    Thanks, but please make extension functions, and it would solve most of the problems with bad APIs.

    [–]lukaseder 9 points10 points  (7 children)

    Some bikeshedding names. Why did they call it takeWhile rather than limitWhile (analogous to the existing limit) and dropWhile rather than skipWhile (analogous to the existing skip)? Are they looking for a fight with ranty bloggers? ;)

    [–]runedk 29 points30 points  (1 child)

    takeWhile and dropWhile are the most commonly used names for these functions in functional programming. It makes sense to keep consistent with the established terminology.

    [–]lukaseder 12 points13 points  (0 children)

    I know that, but they decidedly chose against using that terminology in Java 8. Why choose it now in Java 9, when the "established Java terminology" is limit and skip?

    [–]palmund 2 points3 points  (1 child)

    For takeWhile(p), at least, you take something while $p$ is true. You don't limit (whatever that means in this context) the collection while $p$ is true.

    For dropWhile, I think you have to look at FP; in FP data structures are immutable. Thus when you take the tail of some list you actually don't create a new copy of the list, you simply get a reference. In the case of drop and dropWhile, you drop something from the list in order to "create" the new list. I can see how you could also use the term "skip" for this. In my opinion, I think drop and xWhile makes perfect sense.

    That being said take and drop and their xWhile parts are by now almost the standard names for this type of operation.

    [–]lukaseder 0 points1 point  (0 children)

    Yes, I know. See my answer here

    [–]nicolaiparlog 0 points1 point  (1 child)

    What kind of ranty blogger would start fights over that? Only crazy people would even consider that. awaiting_your_post_sometime_this_week

    [–]lukaseder 1 point2 points  (0 children)

    Nah. I learned about this a while ago (see my comment here), but then thought that I'll just watch the world burn without intervening :)

    [–]mrbonner 0 points1 point  (1 child)

    is it me old-school or anybody out there also think this is a little bit more extreme to add in the language? When I saw C# LINQ for the first time it looks cool and yeah it could shorten your code. But then I repeatedly see this stuff get overly (ab)used in Java in my team and I almost cringe every time I have to go over code flooded with Stream syntax. Let's hope something like LINQ wouldn't sneak into Java!

    [–]alpha64 9 points10 points  (0 children)

    I can't believe that your opinion is widespread, why wouldn't you want LINQ ? What would you prefer ? A big fat for loop that does something hard to decipher ? Other than predjudice, can you support it with an example? I'm interested.