Concat Publishers с Reractor, но различные элементы процесса - PullRequest
0 голосов
/ 21 сентября 2019

У меня что-то подобное:

public static void main(String[] args) {
    Flux<Integer> lower = Flux.just(1, 2, 3, 4, 5);
    Flux<Integer> upper = Flux.just(6, 7, 8, 9, 10);
    Flux<Integer> total = Flux.concat(lower, upper);
    total.subscribe(n -> System.out.println(n * 1));
}

возможно ли умножить нижние элементы на 1 и верхние элементы на 2?В реальном мире я не мог различить, каким издателем был создан элемент.

1 Ответ

1 голос
/ 21 сентября 2019

Конечно.Используйте оператор map() на обоих:

Flux<Integer> lower = Flux.just(1, 2, 3, 4, 5).map(i -> i * 1); // completely unnecessary, but you asked for it
Flux<Integer> upper = Flux.just(6, 7, 8, 9, 10).map(i -> i * 2);
Flux<Integer> total = Flux.concat(lower, upper);
total.subscribe(n -> System.out.println(n));
...