I know what is the purpose and how to handle Stream as a query output, i.e.:
Stream<Person> findAll();
However, recently I stumbled upon org.springframework.data.util.Streamable<T>
, used in the same way as a Stream
:
Streamable<Person> findByNameContaining(String name, Sort sort);
What is the use case of Streamable
?
interface Streamable
Functional Interface: This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Spring doc
Stream from java.util
is just an interface.
Streamable was created from Spring as a functional interface that extended Iterable<T>
Streamable also has some default methods and some static ones. But it was used to be able to provide an Iterator as a lambda function taking advantage of how functional interfaces work.
That's only technical info.
Practical now from what I understand it's main use is to convert an Iterable<T>
into a Stream<T>
Iterable<String> it = Arrays.asList("a","b","c");
Stream<String> s = Streamable.of(it).stream();
It didn't exist an easy way to directly convert an Iterable<T>
into a Stream<T>
therefore they invented it.
You can find most of those uses here Uses of Spring Streamable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With