package dev.inmo.micro_utils.coroutines import kotlinx.coroutines.flow.* import kotlin.js.JsName import kotlin.jvm.JvmName inline fun Flow>.flatMap( crossinline mapper: suspend (T) -> R ) = flow { collect { it.collect { emit(mapper(it)) } } } @JsName("flatMapIterable") @JvmName("flatMapIterable") inline fun Flow>.flatMap( crossinline mapper: suspend (T) -> R ) = map { it.asFlow() }.flatMap(mapper) inline fun Flow>.flatMapNotNull( crossinline mapper: suspend (T) -> R ) = flatMap(mapper).takeNotNull() @JsName("flatMapNotNullIterable") @JvmName("flatMapNotNullIterable") inline fun Flow>.flatMapNotNull( crossinline mapper: suspend (T) -> R ) = flatMap(mapper).takeNotNull() fun Flow>.flatten() = flatMap { it } @JsName("flattenIterable") @JvmName("flattenIterable") fun Flow>.flatten() = flatMap { it }