Thanks for the suggestion, I have this function no...
# codereview
a
Thanks for the suggestion, I have this function now:
Copy code
inline fun <T> Collection<T>.flattenBy(transform: (T) -> Collection<T>?): List<T> {
    val destination = ArrayList<T>()
    val queue = LinkedList<T>(this)
    while (queue.isNotEmpty()) {
        queue.removeFirst().let {
            destination.add(it)
            transform(it)?.run { queue.addAll(0, this) }
        }
    }
    return destination
}