When targeting Java interop, what type should one use for a lazy collection?
Sequence<T>
makes the most sense for Kotlin callers due to extension functions on it being lazy by default, but forces Java callers to deal with a Kotlin stdlib type and convert the sequence iterator manually (sequence does not extend iterable!)Iterable<T>
makes sense for Java callers due to implicit usage in for loops, but will cause unsuspecting Kotlin callers to accidentally drop laziness due to non-lazy extension functionsStream<T>
is optimal for both Java and Kotlin callers but may have overhead and is Java 8+ (Kotlin targets 6+)