jaspersmit
05/29/2017, 12:28 PMval childUnitsById = units
.map { if(it.parent != null) it else null }
.filterNotNull()
.groupBy {it.parent!!}
Andreas Sinz
05/29/2017, 12:33 PMmapNotNull { }
jaspersmit
05/29/2017, 12:34 PMval childUnitsById = units
.mapNotNull { if(it.parent != null) it else null }
.groupBy {it.parent!!}
menegatti
05/29/2017, 12:38 PMjaspersmit
05/29/2017, 12:38 PMmenegatti
05/29/2017, 12:38 PMAndreas Sinz
05/29/2017, 12:39 PMparent != null
and then group them together? you could do that with filter { it.parent != null }
toomenegatti
05/29/2017, 12:39 PMjaspersmit
05/29/2017, 12:39 PMmenegatti
05/29/2017, 12:42 PMjaspersmit
05/29/2017, 12:44 PMmenegatti
05/29/2017, 12:50 PMjaspersmit
05/29/2017, 12:59 PMcedric
05/29/2017, 2:27 PM!!
would be to create a List<ParentType>
(not nullable), so you'd have to generate that list first. Means you'd iterate twice, but you'd get rid of the !!
.null
by the time you get there)jaspersmit
05/29/2017, 2:40 PMgjesse
05/29/2017, 4:44 PM!!
needed
val childUnitsById = units
.filter { it.parent != null }
.groupBy { it.parent }
cedric
05/29/2017, 4:45 PMit.parent
?gjesse
05/29/2017, 4:46 PMdata class Node(val parent: Node?, val id: String) {
override fun toString(): String {
return "Node(id='$id')"
}
}