diff --git a/README.adoc b/README.adoc index b717726..44defe6 100644 --- a/README.adoc +++ b/README.adoc @@ -213,7 +213,7 @@ class FakeMessageService : MessageService { override fun latest(): List { val count = Random.nextInt(1, 15) - return (0..count).map { + return (1..count).map { val user = users.values.random() val userQuote = usersQuotes.getValue(user.name).invoke() @@ -244,7 +244,7 @@ The main task of the `FakeMessageService` class is to generate a random number o [source,kotlin] ----- val count = Random.nextInt(1, 15) -return (0..count).map { +return (1..count).map { val user = users.values.random() val userQuote = usersQuotes.getValue(user.name).invoke() @@ -252,7 +252,7 @@ return (0..count).map { }.toList() ----- -In Kotlin, to generate a https://kotlinlang.org/docs/reference/ranges.html[range] of integers all we need to do is say `(0..count)`. We then apply a `map()` function to transform each number into a message. +In Kotlin, to generate a https://kotlinlang.org/docs/reference/ranges.html[range] of integers all we need to do is say `(1..count)`. We then apply a `map()` function to transform each number into a message. Notably, the selection of a random element from any collection is also quite simple. Kotlin provides an extension method for collections, which is called `random()`. We use this extension method to select and return a user from the list: `users.values.random()` @@ -1414,4 +1414,4 @@ fun `test that messages streamed to the API is stored`() { } ----- -This was the final part in the tutorial. We started with a simple chat application in which the UI was polling for new messages while the backend was blocking when running the database queries. We gradually added features to the application and migrated it to the reactive Spring stack. The backend is now fully asynchronous, making use of Spring WebFlux and Kotlin coroutines. \ No newline at end of file +This was the final part in the tutorial. We started with a simple chat application in which the UI was polling for new messages while the backend was blocking when running the database queries. We gradually added features to the application and migrated it to the reactive Spring stack. The backend is now fully asynchronous, making use of Spring WebFlux and Kotlin coroutines. diff --git a/src/main/kotlin/com/example/kotlin/chat/service/FakeMessageService.kt b/src/main/kotlin/com/example/kotlin/chat/service/FakeMessageService.kt index 052a89b..4c4e9ca 100644 --- a/src/main/kotlin/com/example/kotlin/chat/service/FakeMessageService.kt +++ b/src/main/kotlin/com/example/kotlin/chat/service/FakeMessageService.kt @@ -23,7 +23,7 @@ class FakeMessageService : MessageService { override fun latest(): List { val count = Random.nextInt(1, 15) - return (0..count).map { + return (1..count).map { val user = users.values.random() val userQuote = usersQuotes.getValue(user.name).invoke()