Skip to content

Commit 145a47e

Browse files
committed
doc update
1 parent 468c64f commit 145a47e

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
1-
* https://kotlinlang.org/docs/reference/scope-functions.html
2-
* https://www.manning.com/books/kotlin-in-action
3-
41
# kotlin-dsl-lambda-workshop
52

3+
* reference
4+
* https://kotlinlang.org/docs/reference/scope-functions.html
5+
* https://www.manning.com/books/kotlin-in-action
6+
67
## extension function
7-
* Adding methods to other people’s classes:
8-
extension functions and properties
9-
* Conceptually, an extension function is a simple thing: it’s a function that can be
10-
called as a member of a class but is defined outside of it
11-
* package strings
12-
fun String.lastChar(): Char = this.get(this.length - 1)
13-
* The receiver type (String) is the type on which the extension is
14-
defined, and the receiver object (this) is the instance of that type
15-
* as in a regular method, you can omit this: fun String.lastChar(): Char = get(length - 1)
16-
178
* top-level function
18-
* when you compile the file, some classes will be pro-
19-
duced, because the JVM can only execute code in classes
20-
* you can
21-
place functions directly at the top level of a source file, outside of any class
9+
* JVM can only execute code in classes
10+
* you can place functions directly at the top level of a source file, outside of any class
11+
* when you compile the file, some classes will be produced
12+
```
2213
package strings // filename: join.kt
2314
fun joinToString(...): String { ... }
2415
@@ -27,6 +18,15 @@
2718
public class JoinKt { // Corresponds to join.kt, the filename
2819
public static String joinToString(...) { ... }
2920
}
21+
```
22+
* it’s a function that can be called as a member of a class but is defined outside of it
23+
* example
24+
```
25+
fun String.lastChar(): Char = this.get(this.length - 1)
26+
fun String.lastChar(): Char = get(length - 1) // this is implicit
27+
```
28+
* receiver type: String - type on which the extension is defined
29+
* receiver object: this - the instance of that type
3030
3131
## lambdas with receivers
3232
* the ability to call methods of a different object in the body of a

0 commit comments

Comments
 (0)