Davide Giuseppe Farella
01/24/2019, 11:25 AM@Suppress("UNCHECKED_CAST")
pairsListOfNullableApiParamAndNullableString
.filterNot { it.first == null || it.second == null }
.map { it as Pair<ApiParam, String> }
elizarov
01/24/2019, 11:30 AMpairsListOfNullableApiParamAndNullableString
.mapNotNull { if (it.first != null && it.second != null) Pair(it.first, it.second) else null }
Davide Giuseppe Farella
01/24/2019, 11:38 AMarekolek
01/24/2019, 11:55 AMpairsListOfNullableApiParamAndNullableString: List<Pair<ApiParam?, String?>>
? I’d think that it should, since first
and second
are val
, but somehow it doesn’t work https://pl.kotl.in/BJqjvQPXEarekolek
01/24/2019, 12:02 PMpairsListOfNullableApiParamAndNullableString
.mapNotNull { (first, second) ->
first?.let { second?.let { first to second } }
}
hmole
01/24/2019, 12:13 PMinline fun <A, B, R> zip(a: A?, b: B?, func: (A, B) -> R): R? =
if (a != null && b != null)
func(a, b) else null
val list: List<Pair<String?, String?>> = emptyList()
val result: List<Pair<String, String>> = list.mapNotNull { (first, second) -> zip(first, second, ::Pair) }
Davide Giuseppe Farella
01/24/2019, 12:18 PM