From 629e23ae3126dcf5190eaa6b321792efd25e12f9 Mon Sep 17 00:00:00 2001 From: Steven Schoen Date: Mon, 8 Jul 2019 11:17:19 -0700 Subject: [PATCH] Use emptyList rather than empty listOf I think for beginners, `listOf()` is more confusing than `emptyList()`. `orEmpty()` would also work. --- .../02_BlockingRequest.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Introduction to Coroutines and Channels/02_BlockingRequest.md b/Introduction to Coroutines and Channels/02_BlockingRequest.md index e9215f8..15b2145 100644 --- a/Introduction to Coroutines and Channels/02_BlockingRequest.md +++ b/Introduction to Coroutines and Channels/02_BlockingRequest.md @@ -33,7 +33,7 @@ fun loadContributorsBlocking(req: RequestData) : List { .getOrgReposCall(req.org) // #1 .execute() // #2 .also { logRepos(req, it) } // #3 - .body() ?: listOf() // #4 + .body() ?: emptyList() // #4 return repos.flatMap { repo -> service @@ -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 Response>.bodyList(): List { - return body() ?: listOf() + return body() ?: emptyList() } ```