The for loop looks like
ImmutableListMultiMap.<Key, Value>Builder builder
= ImmutableListMultiMap.<Key, Value>newBuilder();
for (int i = 0; i < Math.min(keys.length(), values.length()); i++) {
builder.put(keys.at(i), values.at(i));
}
A possible first step in Guava / Java 8 is
Streams.zip(keys, values, zippingFunction)
I think zippingFunction
needs to return a map entry, but there isn't a publicly constructable list entry. So the "most" functional way I can write this is with a zipping function that returns a Pair, which I'm not sure exists in Guava, or returns a two-element list, which is a mutable type that does not properly connote there are exactly 2 elements.
This would be desired if I could create a map entry:
Streams.zip(keys, values, zippingFunction)
.collect(toImmutableListMultimap(e -> e.getKey(), e.getValue())
This seems like the best way, except it's not possible, and the zip into entries and unzip from entries still seems roundabout. Is there a way to make this possible or a way it can be improved?