@Test
public void collect() {

    Callable<List<Integer>> as = new Callable<List<Integer>>() {
        @Override
        public List<Integer> call() throws Exception {
            return new ArrayList<Integer>();
        }
    };
    TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
    Flowable.range(1, 10)
    .parallel()
    .collect(as, new BiConsumer<List<Integer>, Integer>() {
        @Override
        public void accept(List<Integer> a, Integer b) throws Exception {
            a.add(b);
        }
    })
    .sequential()
    .flatMapIterable(new Function<List<Integer>, Iterable<Integer>>() {
        @Override
        public Iterable<Integer> apply(List<Integer> v) throws Exception {
            return v;
        }
    })
    .subscribe(ts);
    ts.assertValueSet(new HashSet<Integer>(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)))
    .assertNoErrors()
    .assertComplete();
}