My goal is to unwrap a list of singles of list of ints, and get all it's elements, in order to put it on a list.
List<Single<List<Int>>> listOfSinglesOfListofInts = getListSingleListType(); // random method that gives us that.
List<Int> intList = new ArrayList<>();
My goal is to move move all Int contents from listOfSinglesOfListOfInts to listInt. Here is what I tried:
ListOfSinglesOfListOfInt.stream().map(
singleListOfInts -> singleListOfInts.map(
listOfInts -> intList.addAll(listOfInts)
)
);
return listInt;
The size of listInt is always 0.
What would be the correct way of accomplishing this?
map
operations do not run until the Flowable
chain is completed. This Flowable
is set up, but is not executed. What you probably want to do is run the Flowable
through a blocking collector after flattening the shape. Try this:
return Flowable.fromIterable(listOfSingleOfListofInt)
.flatMap(singleOfListofInt -> singleOfListofInt.toFlowable())
.flatMap(listofInt -> Flowable.fromIterable(listofInt))
.toList()
.blockingGet();
Flowable.fromIterable(listOfSingleOfListofInt)
:
List<Single<List<Int>>>
into Flowable<Single<List<Int>>>
flatMap(singleOfListofInt -> singleOfListofInt.toFlowable())
:
Flowable<Single<List<Int>>>
into Flowable<List<Int>>
flatMap(listofInt -> Flowable.fromIterable(listofInt))
:
Flowable<List<Int>>
into Flowable<Int>
toList()
:
Flowable<Int>
into Signle<List<Int>>
blockingGet()
Signle<List<Int>>
into List<Int>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With