Skip to content

Commit 5df0480

Browse files
authored
feat: avoid "string" as parameter name to improve readability (#4146)
* feat: avoid "string" as parameter name to improve readability * feat: minor change in name after code review
1 parent 6749ce4 commit 5df0480

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

docs/topics/tour/kotlin-tour-functions.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ Kotlin allows you to write even more concise code for functions by using lambda
276276
For example, the following `uppercaseString()` function:
277277

278278
```kotlin
279-
fun uppercaseString(string: String): String {
280-
return string.uppercase()
279+
fun uppercaseString(text: String): String {
280+
return text.uppercase()
281281
}
282282
fun main() {
283283
println(uppercaseString("hello"))
@@ -290,7 +290,7 @@ Can also be written as a lambda expression:
290290

291291
```kotlin
292292
fun main() {
293-
println({ string: String -> string.uppercase() }("hello"))
293+
println({ text: String -> text.uppercase() }("hello"))
294294
// HELLO
295295
}
296296
```
@@ -304,10 +304,10 @@ Within the lambda expression, you write:
304304
* the function body after the `->`.
305305

306306
In the previous example:
307-
* `string` is a function parameter.
308-
* `string` has type `String`.
307+
* `text` is a function parameter.
308+
* `text` has type `String`.
309309
* the function returns the result of the [`.uppercase()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/uppercase.html)
310-
function called on `string`.
310+
function called on `text`.
311311

312312
> If you declare a lambda without parameters, then there is no need to use `->`. For example:
313313
> ```kotlin
@@ -328,7 +328,7 @@ To assign a lambda expression to a variable, use the assignment operator `=`:
328328
329329
```kotlin
330330
fun main() {
331-
val upperCaseString = { string: String -> string.uppercase() }
331+
val upperCaseString = { text: String -> text.uppercase() }
332332
println(upperCaseString("hello"))
333333
// HELLO
334334
}
@@ -406,7 +406,7 @@ For example: `(String) -> String` or `(Int, Int) -> Int`.
406406
This is what a lambda expression looks like if a function type for `upperCaseString()` is defined:
407407

408408
```kotlin
409-
val upperCaseString: (String) -> String = { string -> string.uppercase() }
409+
val upperCaseString: (String) -> String = { text -> text.uppercase() }
410410

411411
fun main() {
412412
println(upperCaseString("hello"))
@@ -462,7 +462,7 @@ any parameters within the parentheses:
462462
```kotlin
463463
fun main() {
464464
//sampleStart
465-
println({ string: String -> string.uppercase() }("hello"))
465+
println({ text: String -> text.uppercase() }("hello"))
466466
// HELLO
467467
//sampleEnd
468468
}

0 commit comments

Comments
 (0)