Reactor系列(十三)zipWith壓縮

java#reactor#flux#zip

壓縮java

視頻講解: https://www.bilibili.com/vide...

FluxMonoTestCase.javareact

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));
    }
}

結果:api

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分鐘視頻學習
ide

相關文章
相關標籤/搜索