Hacker News new | ask | show | jobs
by kodfodrasz 3504 days ago
the Stream API is nice, but it is not extensible. I guess you have mistaken LINQ with the SQL style LINQ queryes, but it is actually a pack of feautures, the basis of all is the Extension Methods. Every LINQ query is just syntactic sugar for composed of some extension methods to IEnumerable<T>. Without that LINQ is a bunch of extension methods giving an extensible fluent API much like the Streams API, but with true extensibility.

How do you extend the the java Stream API? for LINQ you just drop in a few extra extension methods for IEnumerable<T>, IOrederedEmumerable<T>, IQueryable<T>, etc.

How do you reverse a stream in java? (I know you need to evaluate the whole stream for that) You can write a utility method, but that will break the fluent readable logic. In C# you can do the very same thing, with the same method usable as an extension method keeping the readable fluent expression.

Starting a stream is a PITA itself, as it differs for Iterables, Arrays, Collections... Been there, done that. Not that with some utilities these could not be overcome, but it was an inferior experience to LINQ.

1 comments

> How do you reverse a stream in java?

By calling .reverse() on it, and making it iterate the other way around?

> extension methods

Extension methods are something that’s really really problematic, and easy to create confusion with.

That said, I’d just import the functions I want to call on the stream into my local namespace with import static.

When i last used the stream api i don't remember it had a reverse functionality. Still that was an example only.

Edit: Just checked: https://docs.oracle.com/javase/8/docs/api/java/util/stream/S... no reverse().

Fyi for 1 year I have been working on a Stream API heavy app. Now working on a C# project with quite some LINQ. I know both sides to some extent...