Reactor系列(十三)zipWith压缩

#java#reactor#flux#zip#

压缩

视频讲解: https://www.bilibili.com/video/av80703840/

Reactor系列(十三)zipWith压缩_第1张图片

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 stringFlux1 = Flux.just("a","b","c","d","e");
        Flux stringFlux2 = Flux.just("f","g","h","i");
        Flux stringFlux3 = Flux.just("1","2","3","4");
        //方法一zipWith
        stringFlux1.zipWith(stringFlux2).subscribe(x -> log.info("->{}",x));
        System.out.println();
        //方法二zip
        Flux> 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]

你可能感兴趣的:(Reactor系列(十三)zipWith压缩)