SHOW:
|
|
- or go back to the newest paste.
1 | let compatiblePreferences = rawValues.filter { defaults[$0.key] != nil } | |
2 | rawValues = defaults.merging(compatiblePreferences) { (_, new) in new } | |
3 | ||
4 | // My understanding is that Swift lambdas can have anonymous parameters: | |
5 | ||
6 | rawValues.filter { // no named lambda parameter here | |
7 | defaults[$0.key] != nil | |
8 | } | |
9 | ||
10 | // or named parameters | |
11 | ||
12 | rawValues.filter { value in // `$0` is named value and `in` is used to finish statement | |
13 | defaults[value.key] != nil | |
14 | } | |
15 | ||
16 | // That helps us understand the second line: | |
17 | ||
18 | defaults.merging(compatiblePreferences) { (_, new) in new } | |
19 | ||
20 | // It can be reformatted as: | |
21 | ||
22 | defaults.merging(compatiblePreferences) { (_, new) in // 2 names parameters for the conflicting values of both lists; note that `_` tells Swift to ignore the first parameter; we don't need it so we don't name it | |
23 | - | new // implicit `return` of new -> we always pick new value on conflicting key |
23 | + | new // implicit `return` of new -> we always pick new value on conflicting key |
24 | } |