Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: avoid "string" as parameter name to improve readability #4146

Merged
merged 2 commits into from
May 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions docs/topics/tour/kotlin-tour-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ Kotlin allows you to write even more concise code for functions by using lambda
For example, the following `uppercaseString()` function:

```kotlin
fun uppercaseString(string: String): String {
return string.uppercase()
fun uppercaseString(text: String): String {
return text.uppercase()
}
fun main() {
println(uppercaseString("hello"))
Expand All @@ -290,7 +290,7 @@ Can also be written as a lambda expression:

```kotlin
fun main() {
println({ string: String -> string.uppercase() }("hello"))
println({ text: String -> text.uppercase() }("hello"))
// HELLO
}
```
Expand All @@ -304,10 +304,10 @@ Within the lambda expression, you write:
* the function body after the `->`.

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

> If you declare a lambda without parameters, then there is no need to use `->`. For example:
> ```kotlin
Expand All @@ -328,7 +328,7 @@ To assign a lambda expression to a variable, use the assignment operator `=`:

```kotlin
fun main() {
val upperCaseString = { string: String -> string.uppercase() }
val upperCaseString = { text: String -> text.uppercase() }
println(upperCaseString("hello"))
// HELLO
}
Expand Down Expand Up @@ -406,7 +406,7 @@ For example: `(String) -> String` or `(Int, Int) -> Int`.
This is what a lambda expression looks like if a function type for `upperCaseString()` is defined:

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

fun main() {
println(upperCaseString("hello"))
Expand Down Expand Up @@ -462,7 +462,7 @@ any parameters within the parentheses:
```kotlin
fun main() {
//sampleStart
println({ string: String -> string.uppercase() }("hello"))
println({ text: String -> text.uppercase() }("hello"))
// HELLO
//sampleEnd
}
Expand Down