You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/04_functional/01_Higher-Order Functions.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,11 +22,11 @@ fun main() {
22
22
23
23
</div>
24
24
25
-
1.Declaring a higher-order function. It takes two integer parameters, `x` and `y`. Additionally, it takes another function `operation` as a parameter. The `operation` parameters and return type are also defined in the declaration.
26
-
2. The higher order functions returns the result of `operation` invocation with the supplied agruments.
27
-
3.Declaring a function that matches the `operation`signature.
28
-
4.Invoking the higher-order function passing in two integer values and the function argument `::sum`. `::` is the notation that references a function by name in Kotlin.
29
-
5.Invoking the higher-order function passing in a lambda as a function argument. Looks more clear, doesn't it?
25
+
1.Declares a higher-order function. It takes two integer parameters, `x` and `y`. Additionally, it takes another function `operation` as a parameter. The `operation` parameters and return type are also defined in the declaration.
26
+
2. The higher order function returns the result of `operation` invocation with the supplied agruments.
27
+
3.Declares a function that matches the `operation`signature.
28
+
4.Invokes the higher-order function passing in two integer values and the function argument `::sum`. `::` is the notation that references a function by name in Kotlin.
29
+
5.Invokes the higher-order function passing in a lambda as a function argument. Looks clearer, doesn't it?
30
30
31
31
### Returning Functions
32
32
@@ -47,8 +47,8 @@ fun main() {
47
47
48
48
</div>
49
49
50
-
1.Declaring a higher-order function that returns a function.
51
-
2.Declaring a function matching the signature.
52
-
3.Invoking`operation` to get the result assigned to a variable. Here `func` becomes `square` which is returned by `operation`.
53
-
4.Invoking`func`. The `square` function is actually executed.
50
+
1.Declares a higher-order function that returns a function.
51
+
2.Declares a function matching the signature.
52
+
3.Invokes`operation` to get the result assigned to a variable. Here `func` becomes `square` which is returned by `operation`.
53
+
4.Invokes`func`. The `square` function is actually executed.
Copy file name to clipboardExpand all lines: examples/04_functional/03_extensionFunctions.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Extension Functions and Properties
2
2
3
-
Kotlin lets you add new members to any class with the [extensions](https://kotlinlang.org/docs/reference/extensions.html) mechanism. Namely, there are two types of extensions: extension functions and extension properties. They look pretty much like usual functions and properties with the only difference: you need to specify the type that you extend.
3
+
Kotlin lets you add new members to any class with the [extensions](https://kotlinlang.org/docs/reference/extensions.html) mechanism. Namely, there are two types of extensions: extension functions and extension properties. They look a lot like normal functions and properties but with one important difference: you need to specify the type that you extend.
1.Defining simple models of `Item` and `Order`. `Order` can contain a collection of `Item` objects.
32
-
2.Adding extension functions for the `Order` type.
33
-
3.Adding an extension property for the `Order` type.
34
-
4.Calling extension functions directly on an instance of `Order`.
35
-
5.Accessing the extension property on an instance of `Order`.
31
+
1.Defines simple models of `Item` and `Order`. `Order` can contain a collection of `Item` objects.
32
+
2.Adds extension functions for the `Order` type.
33
+
3.Adds an extension property for the `Order` type.
34
+
4.Calls extension functions directly on an instance of `Order`.
35
+
5.Accesses the extension property on an instance of `Order`.
36
36
37
37
It is even possible to execute extensions on `null` references. In an extension function, you can check the object for `null` and use the result in your code:
0 commit comments