3 ms·
> 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 .col
by 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.