Combining two Iterables using standard library -- or -- map with multiple Iterables

guava, xtend, xtext

Solution

final Iterator it = vals.iterator();
expected = Iterables.transform(keys, new Function<String, Pair>() {
    public Pair apply(String key) {
        return new Pair(key, it.next());
    }
});

Added by A.H.:

In Xtend this looks like this:

val valsIter = vals.iterator()
val paired = keys.map[ k | k -> valsIter.next ]

Problem

When given two `Iterables` ``` val keys = newLinkedList('foo', 'bar', 'bla') val vals = newLinkedList(42, 43, 44) ``` I want to correlate each item in both lists like this: ``` val Iterable<Pair<String, Integer>> expected = newLinkedList('foo'->42, 'bar'->43, 'bla'->44) ``` OK, I could do it by hand iterating over both lists. On the other hand this smells like something where - some standard function is available in Xtend or guava or - some neat trick will do it in one line. For examples in Python this would be a no-brainer, because their map function can take multiple lists. How can this be solved using Xtend2+ with miniumum code?

Original source