Hector Ricardo
Hector Ricardo

Reputation: 559

Difference between CharSequence and Sequence<Char> in Kotlin?

In Kotlin, a Sequence<T> is a container whose operations on it (like map, filtering, etc..) are done lazily. Like Java Streams.

A CharSequence is just a supertype/interface of several String-like types, like String, StringBuilder, etc..

So a CharSequence is not processed lazily, right? It's processed greedily.

It just (unfortunately) happens that Kotlin chose the name Sequence to refer to "streams", but also inherited the term/type CharSequence from Java, thereby creating some confusion.

Am I right?

Upvotes: 1

Views: 373

Answers (0)

Related Questions