Skip to content

Instantly share code, notes, and snippets.

@gonaumov
Created May 1, 2022 10:25
Show Gist options
  • Save gonaumov/6da96cd2af20a54067811fa121b8a190 to your computer and use it in GitHub Desktop.
Save gonaumov/6da96cd2af20a54067811fa121b8a190 to your computer and use it in GitHub Desktop.
Kotlin sequences demo from a JetBrains tiny task
/**
* I am using this task to make a demonstration about Kotlin sequences.
* @author Georgi Naumov
* [email protected] for contacts and suggestions.
*/
const val INPUT_SIZE = 5
fun readSequence(iteration: Int): Sequence<String> {
var count = iteration
return generateSequence {
if (--count >= 0) readln() else null
}
}
fun main() {
println(readSequence(INPUT_SIZE).toList().joinToString(" "))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment