In Haskell there is a function called map
, which takes a List of Type A
and a function f
, mapping values of type A
to values of type B
. It returns a list of type B
, such that each element of the result list originates from a call of f
to a value in the input list.
For example, given
- a list
m = ['a', 'b', 'c']
, - and a function
f = {'a' -> 1, 'b' -> 2, 'c' -> 3}
, - then
map(m, f) = [1, 2, 3]
.
Is there a library, usable with Java 7, that offers something like the map
function? I already viewed apache CollectionUtils and found things like forAllDo and transform, but they don't allow retuning a collection of a completely different type. Googling for other libraries failed for the same reason.
To be clear: I know how to solve the problem by myself, but I strongly feel that there must already exist a good library that performs this task more generally.
Bonus question: Is there some equivalent to Haskell functors (i.e. move from collections to iterables) usable in Java 7? Further explanation: Is there a map function which takes an Iterable<A>
instead of Collection<A>
and returns an Iterable<B>
instead of Collection<B>
(provided by a fitting function f
)?