Skip to content
This repository has been archived by the owner on May 17, 2023. It is now read-only.

Use emptyList rather than empty listOf #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Introduction to Coroutines and Channels/02_BlockingRequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fun loadContributorsBlocking(req: RequestData) : List<User> {
.getOrgReposCall(req.org) // #1
.execute() // #2
.also { logRepos(req, it) } // #3
.body() ?: listOf() // #4
.body() ?: emptyList() // #4

return repos.flatMap { repo ->
service
Expand All @@ -60,12 +60,12 @@ If the HTTP response contains an error, this error will be logged here.
Lastly, we need to get the body of the response, which contains the desired data.
For simplicity in this tutorial, we'll use an empty list as a result in case
there is an error, and log the corresponding error (`#4`).
To avoid repeating `.body() ?: listOf()` over and over,
To avoid repeating `.body() ?: emptyList()` over and over,
we declare an extension function `bodyList`:

```kotlin
fun <T> Response<List<T>>.bodyList(): List<T> {
return body() ?: listOf()
return body() ?: emptyList()
}
```

Expand Down