-
Notifications
You must be signed in to change notification settings - Fork 4.3k
update: clarifications on basic functions usage #5155
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
base: master
Are you sure you want to change the base?
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
866baf7 to
397049f
Compare
docs/topics/functions.md
Outdated
| ``` | ||
|
|
||
| Such parameters are also referred to as _optional parameters_. | ||
| If a parameter with default value precedes a parameter with no default value, the default value can only be used by calling |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence is a bit hard to read
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think it needs a bit more nuance when you have trailing lambdas
docs/topics/functions.md
Outdated
| If a function does not return a useful value, its return type is `Unit` (corresponds to the `void` type in Java). | ||
|
|
||
| `Unit` is a type with only one value - `Unit`. | ||
| You don't have to declare this return type, or return `Unit` explicitly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not entirely true. You still very much use Unit in functional types:
fun also(block: T.() -> Unit): T { ... }There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think it's important to clarify that Unit is only assumed as the return type when you use braces to define the function. Otherwise, the type is inferred to the result type of the expression.
ff03575 to
deba8dc
Compare
No description provided.