kirillrakhman
08/16/2016, 5:49 PMvoddan
08/16/2016, 5:51 PMdimsuz
08/16/2016, 6:21 PMval n: Int? = null
n.toString() => "null"
is there a nice way of having it converted to a corresponding String if it's not null and keeping null if it's null?dimsuz
08/16/2016, 6:22 PMn ?: ""
- would always convert to stringilya.gorbunov
08/16/2016, 6:22 PMn?.toString()
dimsuz
08/16/2016, 6:23 PMdimsuz
08/16/2016, 6:23 PMdimsuz
08/16/2016, 6:24 PMilya.gorbunov
08/16/2016, 6:30 PMdimsuz
08/16/2016, 6:34 PMnhaarman
08/17/2016, 2:17 PMinline fun <T, reified R : T> Collection<T>.filterInstanceOf() = filter { it is R }.map { it as R }
yole
08/17/2016, 2:18 PMfilterIsInstance
nhaarman
08/17/2016, 2:18 PMnhaarman
08/17/2016, 2:18 PMdimsuz
08/17/2016, 2:28 PMMap<K,V>.first { (entry) -> Boolean } : V
I.e. filter map entries and get a value of first entry which matchedyole
08/17/2016, 2:31 PMmap.entries.first { … }
dimsuz
08/17/2016, 3:04 PMdimsuz
08/17/2016, 3:04 PMdimsuz
08/18/2016, 1:30 PMMap<K,V> -> Map<V,K>
?dimsuz
08/18/2016, 1:35 PMmap.asSequence().associateTo(hashMapOf(), { it.value to it.key })
, don't know if this is the best solutionorangy
map.entries.associateBy({it.value}, {it.key})
dimsuz
08/18/2016, 1:38 PMbamdmux
08/26/2016, 7:04 AMbamdmux
08/26/2016, 7:04 AMfun <T> Collection<T>.split(n: Int=2) = withIndex().groupBy { (it.index/n) }.values.map{it.map { it.value }}
bamdmux
08/26/2016, 7:09 AMvoddan
08/26/2016, 8:23 AMdimsuz
08/26/2016, 3:41 PMlist1.filter({ listOfIds.contains(it.id) })
is this a good approach or is there something more concise/faster? I do this so often that I sometimes think there's some idiom for this, is there?yole
08/26/2016, 3:42 PMyole
08/26/2016, 3:43 PMdimsuz
08/26/2016, 3:43 PMdifference