Skip to content
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
20 changes: 16 additions & 4 deletions docs/topics/tour/kotlin-tour-intermediate-scope-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ class Client() {
var token: String? = null
fun connect() = println("connected!")
fun authenticate() = println("authenticated!")
fun getData(): String = "Mock data"
fun getData() : String {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could have been kept as a single expression function with also after it, but also is explained after apply (and i'd avoid it using it anyway while explaining scope functions)

println("getting data!")
return "Mock data"
}
}

val client = Client()
Expand All @@ -160,6 +163,7 @@ fun main() {
client.authenticate()
// authenticated!
client.getData()
// getting data!
}
```
{kotlin-runnable="true" id="kotlin-tour-scope-function-apply-before"}
Expand All @@ -179,7 +183,10 @@ class Client() {
var token: String? = null
fun connect() = println("connected!")
fun authenticate() = println("authenticated!")
fun getData(): String = "Mock data"
fun getData() : String {
println("getting data!")
return "Mock data"
}
}
//sampleStart
val client = Client().apply {
Expand All @@ -189,9 +196,10 @@ val client = Client().apply {
}

fun main() {
client.getData()
// connected!
// authenticated!
client.getData()
// getting data!
}
//sampleEnd
```
Expand Down Expand Up @@ -222,7 +230,10 @@ class Client() {
var token: String? = null
fun connect() = println("connected!")
fun authenticate() = println("authenticated!")
fun getData(): String = "Mock data"
fun getData() : String {
println("getting data!")
return "Mock data"
}
}

//sampleStart
Expand All @@ -237,6 +248,7 @@ fun main() {
authenticate()
// authenticated!
getData()
// getting data!
}
}
//sampleEnd
Expand Down