Greetings,
from the documentation on “Control Structures”, Breslav mentioned that the support for parallel iteration of two or more arrays is planned, but not in the stdlib yet. That was in May 23, 2012, and I saw that the Pair<A, B> and Triple<A, B, C> structures now exist. Do the equivalent forEach and map functions also exist? I wrote my own and I’m not sure if I’m just duplicating work I don’t need to.
For Pair:
fun Pair, out Iterable>.forEach(f : (A, B) -> Unit) {
val ia = first.iterator()
val ib = second.iterator()while (ia.hasNext() && ib.hasNext()) {
val va = ia.next()
val vb = ib.next() f(va, vb)
}
}fun Pair, out Iterable>.map(f : (A, B) -> R) : List {
val ia = first.iterator()
val ib = second.iterator()var collect = ArrayList()
while (ia.hasNext() && ib.hasNext()) {
val va = ia.next()
val vb = ib.next() collect.add(f(va, vb))
}
return collect
}
For Triple:
fun Triple, out Iterable, out Iterable>.forEach(f : (A, B, C) -> Unit) {
val ia = first.iterator()
val ib = second.iterator()
val ic = third.iterator()while (ia.hasNext() && ib.hasNext() && ic.hasNext()) {
val va = ia.next()
val vb = ib.next()
val vc = ic.next() f(va, vb, vc)
}
}fun Triple, out Iterable, out Iterable>.map(f : (A, B, C) -> R) : List {
val ia = first.iterator()
val ib = second.iterator()
val ic = third.iterator()var collect = ArrayList()
while (ia.hasNext() && ib.hasNext() && ic.hasNext()) {
val va = ia.next()
val vb = ib.next()
val vc = ic.next() collect.add(f(va, vb, vc))
}
return collect
}