Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Guava equivalent of Scala's flatMap?

Tags:

Looking through https://github.com/google/guava/wiki/FunctionalExplained I see operations like transform, which will transform a list but keep the same cardinality. How can I perform a transform that results in a different cardinality? e.g. (pseudocode) List(1,2,3).transform(i => List(i, i)) -> List(1,1,2,2,3,3)

like image 566
Synesso Avatar asked Dec 07 '12 05:12

Synesso


2 Answers

As of version 13, there is transformAndConcat on FluentIterable.

like image 57
miah Avatar answered Sep 29 '22 10:09

miah


I don't think there's a direct translation, but transform followed by concat should be equivalent.

like image 42
ataylor Avatar answered Sep 29 '22 11:09

ataylor