This file contains 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
fun main() { | |
runBlocking { | |
uuidFlow().collect{ log(it.toString()) } | |
} | |
} | |
fun uuidFlow(): Flow<UUID> = flow { | |
while (true) { | |
delay(100) | |
emit(UUID.randomUUID()) |
This file contains 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
fun main() { | |
uuidSequence().forEach { value -> println(value) } | |
} | |
fun uuidSequence(): Sequence<UUID> = sequence { | |
while (true) { | |
Thread.sleep(100) | |
yield(UUID.randomUUID()) | |
} | |
} |
This file contains 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
abstract class Expression | |
class DoubleExpression(private val value: Double) : Expression() | |
class AdditionExpression( | |
private val left: Expression, | |
private val right: Expression | |
) : Expression() | |
fun main() { |
This file contains 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
abstract class Expression { | |
abstract fun print(sb: StringBuilder) | |
} | |
class DoubleExpression(private val value: Double) : Expression() { | |
override fun print(sb: StringBuilder) { | |
sb.append(value) | |
} | |
} |