DEV Community

Discussion on: Why use Kotlin for Android development? Kotlin benefits, features, versions

Collapse
 
martin profile image
Martin Beentjes

How is the support with Streams today?

Collapse
 
tedhagos profile image
Ted Hagos

There's an article about Kotlin in here;

There's a portion in it where Streams are discussed; short answer is
  • Kotlin has Streams
  • All collection classes in Kotlin already supports the one-time_iterator behavior of java.util.stream.Stream instance
  • Kotlin doesn't need the initial conversion (collection to stream) and the final conversion (stream back to a collection)
  • BUT remember that Java streams are lazily evaluated while Kotlin streams are eagerly evaluated unless you convert to a Sequence
Collapse
 
dianamaltseva8 profile image
Diana Maltseva

If I've understood you right (you mean the ability to work with streams from Java 8 and Kotlin), kotlin-stdlib provides several extension-functions for transferring Java-Stream into Kotlin-Sequence or Kotlin-List kotlinlang.org/api/latest/jvm/stdl....

If you want to know what alternative Kotlin provides Java-Streams with, collections in Kotlin "out of the box" offer operations, available in Java only when transferring collections into Stream.

To compare:

  • Java someList .stream() .map() // some operations .collect(Collectors.toList());
  • Kotlin someList .map()