@@ -19,6 +19,7 @@ val nathan = "Nathan"
19
19
val reka = " Reka"
20
20
val bajram = " Bajram"
21
21
val asuka = " Asuka"
22
+ val riku = " Riku"
22
23
23
24
// cities
24
25
val Canberra = City (" Canberra" )
@@ -31,38 +32,46 @@ fun customer(name: String, city: City, vararg orders: Order) = Customer(name, ci
31
32
fun order (vararg products : Product , isDelivered : Boolean = true) = Order (products.toList(), isDelivered)
32
33
fun shop (name : String , vararg customers : Customer ) = Shop (name, customers.toList())
33
34
34
- val shop = shop(" jb test shop" ,
35
- customer(lucas, Canberra ,
36
- order(reSharper),
35
+ val shop = shop(" jb test shop" ) {
36
+ customer(lucas, Canberra ) {
37
+ order(reSharper)
37
38
order(reSharper, dotMemory, dotTrace)
38
- ),
39
- customer(cooper, Canberra ),
40
- customer(nathan, Vancouver ,
39
+ }
40
+ customer(cooper, Canberra ) {}
41
+ customer(nathan, Vancouver ) {
41
42
order(rubyMine, webStorm)
42
- ),
43
- customer(reka, Budapest ,
44
- order(idea, isDelivered = false ),
45
- order(idea, isDelivered = false ),
43
+ }
44
+ customer(reka, Budapest ) {
45
+ order(isDelivered = false , products = idea)
46
+ order(isDelivered = false , products = idea)
46
47
order(idea)
47
- ),
48
- customer(bajram, Ankara ,
48
+ }
49
+ customer(bajram, Ankara ) {
49
50
order(reSharper)
50
- ),
51
- customer(asuka, Tokyo ,
51
+ }
52
+ customer(asuka, Tokyo ) {
52
53
order(idea)
53
- )
54
- )
54
+ }
55
+ customer(riku, Tokyo ) {
56
+ order(phpStorm, phpStorm)
57
+ order(phpStorm)
58
+ }
59
+ }
55
60
56
- val customers: Map <String , Customer > = shop.customers.map { Pair (it.name, it) }.toMap()
61
+ val customers: Map <String , Customer > = shop.customers.fold(hashMapOf<String , Customer >(), {
62
+ map, customer ->
63
+ map[customer.name] = customer
64
+ map
65
+ })
57
66
58
- val orderedProducts = setOf (idea, reSharper, dotTrace, dotMemory, rubyMine, webStorm)
67
+ val orderedProducts = setOf (idea, reSharper, dotTrace, dotMemory, rubyMine, webStorm, phpStorm )
59
68
60
- val sortedCustomers = listOf (cooper, nathan, bajram, asuka, lucas, reka).map { customers[it] }
69
+ val sortedCustomers = listOf (cooper, nathan, bajram, asuka, lucas, riku, reka).map { customers[it] }
61
70
62
71
val groupedByCities = mapOf (
63
72
Canberra to listOf (lucas, cooper),
64
73
Vancouver to listOf (nathan),
65
74
Budapest to listOf (reka),
66
75
Ankara to listOf (bajram),
67
- Tokyo to listOf (asuka)
76
+ Tokyo to listOf (asuka, riku )
68
77
).mapValues { it.value.map { name -> customers[name] } }
0 commit comments