Re:Functional programming is not popular because it is weird...
by qsort on Tuesday September 14, 2021 @02:07AM
(#28520871)
Java streams are a (limited) version of what you propose.
Something like this is very idiomatic:
[ Parent
| on HN ]
Re:Functional programming is not popular because it is weird...
by kilotaras on Tuesday September 14, 2021 @03:46AM
(#28521584)
Difference 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
Re:Functional programming is not popular because it is weird...
by qsort on Tuesday September 14, 2021 @04:45AM
(#28521963)
> 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.