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
sealed class BookingOutcome |
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
sealed class BookingOutcome | |
class RoomBooked(key: Key, bookingRange: ClosedRange<Instant>) : BookingOutcome() | |
object RoomNotAvailable : BookingOutcome() | |
object HotelClosed : BookingOutcome() |
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
interface BookingService { | |
fun bookRoom(roomId: RoomID): BookingOutcome | |
} |
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
val outcome = bookingService.bookRoom(RoomID("roomIwant")) | |
when (outcome) { | |
} |
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
// we create a sequence that generates prime numbers | |
fun primes(): Sequence<Long> { | |
var i = 2L | |
return generateSequence { i++ } | |
.filter { n -> (2L until n).none { n % it == 0L } } | |
} | |
// we map chars to a unique prime | |
val charToPrime = ('a'..'z').zip(primes().take(26).toList()).toMap() |
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
"""{ | |
"cat": "meow", | |
"dog": "woof" | |
}""".trimIndent() |
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
""" | |
|{ | |
| "cat": "meow", | |
| "dog": "woof" | |
|} | |
""".trimMargin() |
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
val obj = obj { | |
"key" to 3.4 | |
"anotherKey" to arr["test", "test2", 1, 2.433, true] | |
"nullValue" to null | |
"emptyObject" to obj { } | |
"emptyArray" to arr | |
"custom" to ZonedDateTime.now() | |
} | |
println(obj) // 1 |
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
{"key":3.4,"anotherKey":["test","test2",1,2.433,true],"nullValue":null,"emptyObject":{},"emptyArray":[],"custom":"2020-07-15T10:59:19.042965+02:00[Europe/Paris]"} |
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
{ | |
"key": 3.4, | |
"anotherKey": [ | |
"test", | |
"test2", | |
1, | |
2.433, | |
true | |
], | |
"nullValue": null, |
OlderNewer