john.shelley
06/18/2016, 9:58 PMmax
06/18/2016, 10:09 PMsize()
part. I edited previous comment.voddan
06/19/2016, 3:17 AMjohn.shelley
06/19/2016, 3:28 AMsreich
06/19/2016, 3:01 PMsreich
06/19/2016, 3:02 PMvoddan
06/20/2016, 5:27 AMsortWith
is included in stdlib?
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/sort-with.htmlvoddan
06/20/2016, 5:27 AMsortBy
is enough ?kevinmost
06/20/2016, 5:32 AMComparator
for some reason... Like if you're also working with Java, where they're common?jw
06/20/2016, 5:32 AMsortWith
) and the other allows the use of Kotlin lambdas (sortBy
) which delegates to sortWith
jw
06/20/2016, 5:33 AMComparator
factory for the formervoddan
06/20/2016, 5:46 AMjw
06/20/2016, 5:48 AMcleiter
06/20/2016, 8:01 AMreversed()
with a boolean attribute? i have different user sort modes and sometimes i want to reverse the list and sometimes not. there's no elegant way to make the call to reversed()
or not when chaining methods i think. i ended up with an extension methodvoddan
06/20/2016, 8:19 AMinline fun <T, R> T.applyIf(condition: Boolean, op: T.()->R): R
voddan
06/20/2016, 8:20 AMvoddan
06/20/2016, 8:20 AMcleiter
06/20/2016, 8:29 AMapplyIf
sounds like a good general approachfellshard
06/20/2016, 9:48 AMsortBy
is intended for specifying a derived property of objects by which those objects are sorted using the property's default comparator, as opposed to sortWith
where you can hand a more fine-tune comparator definition that isn't the default comparator.fellshard
06/20/2016, 9:58 AMvoddan
06/21/2016, 2:15 PMvoddan
06/21/2016, 2:16 PMval data = mutableMapOf(1 to listOf(1))
val copy = data.mapValues {it.value.toList()}
voddan
06/21/2016, 2:16 PMMap.Entry
in the lambdavoddan
06/21/2016, 2:17 PMcedric
06/21/2016, 2:20 PMval m = mapOf<String, Int>()
val copy = hashMapOf<String, Int>().apply {
m.entries.forEach { e ->
put(e.key, e.value)
}
}
cedric
06/21/2016, 2:20 PMcopy
is mutable at the end here, not sure the best way to make it immutablevoddan
06/21/2016, 2:23 PMvoddan
06/21/2016, 2:24 PMcedric
06/21/2016, 2:25 PMcedric
06/21/2016, 2:25 PM