'Why does ide say "Value captured in a closure" when using Iterable.flatMap but doesn't when using map then flatten in kotlin?

inline fun <T : Any, E : Any> batchQuery(
    paramsToBeChunked: Collection<T>,
    batchSize: Int = 500,
    crossinline queryAction: (params: Collection<T>) -> List<E>
) = paramsToBeChunked.chunked(batchSize).flatMap { queryAction(it) } 

enter image description here

inline fun <T : Any, E : Any> batchQuery(
    paramsToBeChunked: Collection<T>,
    batchSize: Int = 500,
    crossinline queryAction: (params: Collection<T>) -> List<E>
) = paramsToBeChunked.chunked(batchSize).map { queryAction(it) }.flatten()

enter image description here

Is there any potential problem when using flatMap?

IMHO, map, flatten, flatMap are all inline functions, so these two implementations are equivalent, is this right?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source