Created
May 1, 2022 10:25
-
-
Save gonaumov/6da96cd2af20a54067811fa121b8a190 to your computer and use it in GitHub Desktop.
Kotlin sequences demo from a JetBrains tiny task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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