Javaslang / Vavr LinkedHashMap from List

Viewed 1789

Is there a concise, idiomatic way to create an order-preserving map from a Javaslang / Vavr List? List.toMap() returns a plain HashMap, so that doesn't do it. What I have right now is something like this --

listOfKeys.foldLeft(
    LinkedHashMap.<Key, Value>.empty(), 
    (m, k) -> m.put(k, valueFor(k))
);

-- but this seems more verbose than necessary, and possibly less efficient as well.

2 Answers
Related