oday
03/04/2019, 3:55 PMname field, then reconstruct this sortedmap agianPavlo Liapota
03/04/2019, 4:15 PMPavlo Liapota
03/04/2019, 4:18 PModay
03/04/2019, 4:37 PModay
03/04/2019, 4:37 PModay
03/04/2019, 4:37 PModay
03/04/2019, 5:04 PModay
03/04/2019, 5:05 PModay
03/04/2019, 5:13 PMPavlo Liapota
03/04/2019, 5:14 PMTreeMap is first implementation of SortedMap that I found.
Kotlin’s .toSortedMap() also creates TreeMapoday
03/04/2019, 5:16 PMPavlo Liapota
03/04/2019, 5:16 PMPavlo Liapota
03/04/2019, 5:18 PMmapValues creates a new map and it is not SortedMap.oday
03/04/2019, 5:19 PMtoSortedMap inside it, i was doing it twice before, it was wrongoday
03/04/2019, 5:52 PModay
03/04/2019, 5:53 PModay
03/04/2019, 5:53 PMtosortedMap isnt letting me do this because it needs a comparatoroday
03/04/2019, 5:54 PModay
03/04/2019, 5:58 PModay
03/04/2019, 6:01 PModay
03/04/2019, 6:01 PModay
03/04/2019, 6:04 PMPavlo Liapota
03/04/2019, 6:41 PMval carMakesMap = carMakes.values
.flatten()
.filter { carMake -> carMake.name.contains(newText, ignoreCase = true) }
.groupBy { it.name.first() }
Or maybe:
val carMakesMap = carMakes
.mapValues { (_, value) ->
value.filter {carMake -> carMake.name.contains(newText, ignoreCase = true) }
}
.filterValues { it.isNotEmpty() }kevinmost
03/04/2019, 6:52 PM.functionalOperator { ... }.toCustomCollectionImpl() with .functionalOperatorTo(CustomCollectionImpl()) { ... }kevinmost
03/04/2019, 6:52 PM.mapValues { ... }.toSortedMap() with .mapValuesTo(TreeMap()) { ... }oday
03/04/2019, 7:42 PModay
03/04/2019, 7:46 PMcarMakes.mapValues { entry ->
entry.value.filter { carMake ->
carMake.name.contains(newText, ignoreCase = true)
}.groupBy { it.name.first() }.toMap(carMakesMap)
}
but i am still unable to then after all of this, filter the keys to only take those who have notEmpty values (the list belonging to that key is empty because none of its items matched that key (entered through searchbar))oday
03/04/2019, 7:46 PMcarMakes.mapValues { entry ->
entry.value.filter { carMake ->
carMake.name.contains(newText, ignoreCase = true)
}.groupBy { it.name.first() }.toMap(carMakesMap)
}.filterKeys { carMakes[it]!!.isNotEmpty() }kevinmost
03/04/2019, 7:47 PMmapValues, and then the output collection isn't in a format that you want so you do something like toMap(...) or toSortedMap() or anything like that, you could use the version of the transform ending in To, like mapValuesTo and specify a collection to output into as the first parameteroday
03/04/2019, 7:47 PMkevinmost
03/04/2019, 7:49 PMChar keys are like, the first letter in the car make? Like the map is:
[
'a': [],
'b': [],
'c': [CarMake("Chevy")],
'd': [CarMake("Dodge")],
...
]
?kevinmost
03/04/2019, 7:50 PModay
03/04/2019, 7:51 PModay
03/04/2019, 7:51 PModay
03/04/2019, 7:52 PM.filterKeys on it after i filtered the valueskevinmost
03/04/2019, 7:52 PModay
03/04/2019, 7:53 PModay
03/04/2019, 7:53 PModay
03/04/2019, 7:54 PModay
03/04/2019, 7:54 PM.filterKeys { carMakes[it].isNotEmpty() }oday
03/04/2019, 7:54 PModay
03/04/2019, 7:54 PModay
03/04/2019, 7:56 PMkevinmost
03/04/2019, 8:00 PMcarMakes
.mapValuesTo(TreeMap()) { (_, values: List<String>) -> values.filter { it.contains(filter, ignoreCase = true) }}
.filterTo(TreeMap()) { (_, values) -> values.isNotEmpty() }
is there something about this that wouldn't work?oday
03/04/2019, 8:01 PModay
03/04/2019, 8:01 PModay
03/04/2019, 8:01 PMkevinmost
03/04/2019, 8:02 PMkevinmost
03/04/2019, 8:02 PMcarMakes
.values
.flatten()
.filter { it.contains(filter, ignoreCase = true) }
.groupByTo(TreeMap()) { it[0] }kevinmost
03/04/2019, 8:02 PMkevinmost
03/04/2019, 8:17 PMasSequence() in the middle too. .values.asSequence().flatten()....oday
03/04/2019, 8:27 PM