3 ms·
Java streams are a (limited) version of what you propose. Something like this is very idiomatic: myhashmap.entrySet() .stream() .map(Map.En
by qsort 5y ago
Java streams are a (limited) version of what you propose.
Something like this is very idiomatic:
myhashmap.entrySet()
.stream()
.map(Map.Entry::getValue)
.sorted()
.distinct()
.toList()
- carlmr 5y agoI was going to say C# LINQ, too!
- kilotaras 5y agoDifference with pipe operator would be 1. can't be extended. myhashmap.entrySet() .stream() .flattenBars() .toFoo() 2. (As a result of 1) - applies only to streams
- qsort 5y ago> can't be extended They can be extended arbitrarily by defining collectors. The Stream interface is very well designed. For example your "toFoo" would be .collect(Collector(<foo-provider>, <foo-accept>, <foo-merge>, <foo-finisher>)). All of them can be arbitrary functions working on arbitrary types. That's the standard library implementation of "toList", in fact! > applies only to streams You're exactly correct here, but for legacy reasons Java did not have a choice. I'm the first to admit mylist.stream().map(f).toList() is dumb. A list is a functor, dammit! It's the best possible solution given the existing constraints, but it's definitely limited in what it can do.