Reactor系列(十三)zipWith压缩

发布于 2019-12-26  约 4 分钟

java#reactor#flux#zip

压缩

视频讲解: https://www.bilibili.com/vide...

FluxMonoTestCase.java

package com.example.reactor;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.util.function.Tuple3;

@Slf4j
public class FluxMonoTestCase extends BaseTestCase {
    @Test
    public void zip(){
        Flux<String> stringFlux1 = Flux.just("a","b","c","d","e");
        Flux<String> stringFlux2 = Flux.just("f","g","h","i");
        Flux<String> stringFlux3 = Flux.just("1","2","3","4");
        //方法一zipWith
        stringFlux1.zipWith(stringFlux2).subscribe(x -> log.info("->{}",x));
        System.out.println();
        //方法二zip
        Flux<Tuple3<String,String,String>> tuple2Flux = Flux.zip(stringFlux1,stringFlux2,stringFlux3);
        tuple2Flux.subscribe(x -> log.info("->{}",x));
    }
}

结果:

11:28:47.027 [main] INFO com.example.reactor.FluxMonoTestCase - ->[a,f]
11:28:47.028 [main] INFO com.example.reactor.FluxMonoTestCase - ->[b,g]
11:28:47.028 [main] INFO com.example.reactor.FluxMonoTestCase - ->[c,h]
11:28:47.028 [main] INFO com.example.reactor.FluxMonoTestCase - ->[d,i]

11:28:47.029 [main] INFO com.example.reactor.FluxMonoTestCase - ->[a,f,1]
11:28:47.029 [main] INFO com.example.reactor.FluxMonoTestCase - ->[b,g,2]
11:28:47.029 [main] INFO com.example.reactor.FluxMonoTestCase - ->[c,h,3]
11:28:47.029 [main] INFO com.example.reactor.FluxMonoTestCase - ->[d,i,4]

关注公众号,坚持每天3分钟视频学习

阅读 243发布于 2019-12-26

推荐阅读
目录