Is there some standard API or established third party library (I am thinking commons or Guava) that provides in Java the equivalent of zip
or map vector
function in languages like Ruby or Clojure?
(zip '(1 2 3) '(a b c)) '( (1 a) (2 b) (3 c))
So the signature (for two collections) would be:
public static <V,T> List< Pair<V, T> > zip (List<V> vs, List<T> ts);
where Pair
would also be presumably defined in that library. I know its trivial to implement but maybe said library has other functional goodies too.
Advertisement
Answer
There’s no standard per se. I’ve played with Functional Java a bit, and it’s ok for basic stuff.
This was answered in more detail here: https://softwareengineering.stackexchange.com/questions/101352/is-functional-programming-possible-in-java#101361
But you could also consider using something like Scala (which runs on the JVM)