Question

I read through the javadoc and couldn't find anything that resembles it.

Was it helpful?

Solution

No, it does not.

While it does have certain functional programming elements (Predicate, Function), those were to support specific needs and its core focus is not adding functional programming elements for Java (seeing as how it's terribly verbose currently). See this issue for a bit on that.

OTHER TIPS

I think that you don't have a exact inject method.. but you can obtain a similar solution by using the transformValues methods supplied

Maps.transformValues(Map<K,V1> fromMap, Function<? super V1,V2> function)
List.transform(List<F> fromList, Function<? super F,? extends T> function)

Of course you'll need a Function class defined ad hoc to work with the passed parameter of the inject:

class MyFunction<Type, Type>
{
  static String variable;

  Type apply(Type t)
  {
     //do whatever you want with t
     // and storing intermediate result to variable

     // return same t to make this function work like identity
     return t;
  }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top