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/05_stdlib/02_withFunction.md
+1-2Lines changed: 1 addition & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,6 @@
1
1
# with
2
2
3
-
*with* is a function defined in the standard library that can be used to access members of an object in a more concise way, avoiding having to
4
-
prefix each member with the instance name.
3
+
*with* function lets you access members of an object in a short and concise way. Inside the `with` block you can refer to object members without specifying its name as a prefix.
Copy file name to clipboardExpand all lines: examples/05_stdlib/03_filter.md
+4-5Lines changed: 4 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,6 @@
1
1
# filter
2
2
3
-
*filter* is a function defined in the standard library that can be used to filter collection. It takes a predicate as an lambda-parameters.
4
-
3
+
*filter* function enables you to filter collections. It takes a filter predicate as a lambda-parameter. The predicate is applied to each element. Elements that make the predicate `true` are returned in the result collection.
Copy file name to clipboardExpand all lines: examples/05_stdlib/04_map.md
+4-4Lines changed: 4 additions & 4 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
# map
2
2
3
-
*map*is an extension function defined in the standard library that can be used to transform collection into another collection. It takes a transformer as an lambda-parameters.
3
+
*map* extension function enables you to apply a transformation to all elements in a collection. It takes a transformer function as a lambda-parameter.
Copy file name to clipboardExpand all lines: examples/05_stdlib/06_find.md
+7-6Lines changed: 7 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,7 @@
1
-
# find
1
+
# find, findLast
2
+
3
+
`find` and `findLast` functions return the first or the last collection element that matches the given predicate. If there are no such elements, functions return `null`.
2
4
3
-
Returns the first or last element matching the given predicate, or `null` if no such element was found.
Copy file name to clipboardExpand all lines: examples/05_stdlib/07_firstlast.md
+16-20Lines changed: 16 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,9 @@
2
2
3
3
### `first`, `last`
4
4
5
-
Those functions return either the first or last element of the collection or the first/last matching the given predicate.
5
+
These functions return the first and the last element of the collection correspondingly. You can also use them with a predicate; in this case, they return the first or the last element that matches the given predicate.
6
6
7
-
In case of empty collection or if nothing matching the predicate those function throw an `NoSuchElementException`.
8
-
9
-
Lets make some Kotlin!
7
+
If a collection is empty or doesn't contain elements matching the predicate, the functions throw `NoSuchElementException`.
This function splits the original collection into pair of lists, where first list contains elements for which predicate yielded `true`, while second list contains elements for which predicate yielded `false`.
3
+
`partition` function splits the original collection into pair of lists using a given predicate:
Copy file name to clipboardExpand all lines: examples/05_stdlib/10_associateBy.md
+10-8Lines changed: 10 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,11 @@
1
1
# associateBy, groupBy
2
2
3
-
Both functions return a `Map` containing the elements from the given collection indexed by the key returned from `keySelector` function applied to each element.
4
-
If `valueSelector`is also passed it is applied to each element as well.
3
+
Functions `associateBy` and `groupBy` build maps from the elements of a collection indexed by the specified key. The key is defined in the `keySelector` parameter.
4
+
You can also specify an optional `valueSelector`to define what will be stored in the `value` of the map element.
5
5
6
-
The difference between `associateBy` and `groupBy` is the behaviour for values with the same key. `associateBy` takes only last element when `groupBy` takes all elements into collection.
6
+
The difference between `associateBy` and `groupBy` is how they process objects with the same key:
7
+
*`associateBy` uses the last suitable element as the value.
8
+
*`groupBy` builds a list of all suitable elements and puts it in the value.
7
9
8
10
The returned map preserves the entry iteration order of the original collection.
9
11
@@ -37,8 +39,8 @@ fun main() {
37
39
38
40
</div>
39
41
40
-
1.Define data class descirbes a Person.
41
-
2.Define collection of known people.
42
-
3.Build a map from person's phone number to person information.
43
-
4.Build another map from phone number to city where owner lives.
44
-
5.Build the third map which contains cities and people living there.
42
+
1.Defines a data class that descirbes a person.
43
+
2.Defines a collection of people.
44
+
3.Builds a map from phone numbers to their owners' information. `it.phone` is the `keySelector` here. The `valueSelector` is not provided, so the values of the map are `Person` objects themselves.
45
+
4.Builds a map from phone numbers to the cities where owners live. `Person::city` is the `valueSelector` here, so the values of the map contain only cities.
46
+
5.Builds a map that contains cities and people living there. The values of the map are lists of person names.
0 commit comments