tginiotis
11/21/2018, 2:52 PMval sampleList = listOf("one", "two", "three")
val tCount = sampleList.fold(0) { acc, r ->
acc + if (r == "t") {
1
} else {
0
}
}
val wCount = sampleList.fold(0) { acc, r ->
acc + if (r == "w") {
1
} else {
0
}
}
now I have tCount
and wCount
, which I got by going over the list 2 times from the beginning to the end. After one fold operation was finished - the other started. I would rather that the folds would be interleaved
and a tuple2 would be the result