Xavier F. Gouchet
12/06/2019, 12:17 PMval transforms = listOf<(String) -> String>(
{ it.toLowerCase() },
{ it.split(",").first() }
)
val data = listOf("foo, 42", "BAR, 33")
val result = data.mapAll(transforms) // result has ["foo", "bar"]
karelpeeters
12/06/2019, 12:23 PMval result = data.map { transforms.fold(it) { a, t -> t(a) } }
Xavier F. Gouchet
12/06/2019, 12:25 PMadimit
12/06/2019, 1:29 PMzip
. Zippers can merge two lists. Typically into a list of pairs, but you can also zip with a function. In your case, the function you'd zip with is simply function application. So your example is:
listOf<(String) -> String> { it.toLowerCase() }.zip(listOf("FOO", "BAR")) { f, s -> f(s) }
karelpeeters
12/06/2019, 1:30 PMadimit
12/06/2019, 1:30 PM