cyclops.reactive.ReactiveSeq.findFirstOrError()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(1.9k)|赞(0)|评价(0)|浏览(85)

本文整理了Java中cyclops.reactive.ReactiveSeq.findFirstOrError方法的一些代码示例,展示了ReactiveSeq.findFirstOrError的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ReactiveSeq.findFirstOrError方法的具体详情如下:
包路径:cyclops.reactive.ReactiveSeq
类名称:ReactiveSeq
方法名:findFirstOrError

ReactiveSeq.findFirstOrError介绍

[英]Lazy / reactive look up of first value , capturing the first error, if one occurs. If no values are present a NoSuchElementException is returned. For push based reactive-streams (created via Spouts.XXX) data will be pushed to the returned Either on arrival. For pull based Streams (created via ReactiveSeq.XXX) the Stream will be executed when the Either is first accessed.
[中]惰性/被动查找第一个值,如果出现第一个错误,则捕获第一个错误。如果不存在任何值,则返回NoTouchElementException。对于基于推送的反应流(通过Spouts.XXX创建),数据将在到达时推送到返回的服务器。对于基于pull的流(通过ReactiveSeq.XXX创建),当第一次访问其中一个时,将执行该流。

代码示例

代码示例来源:origin: aol/cyclops

@Test
public void combineOneFirstOrError() {
  assertThat(of(1)
      .combine((a, b) -> a < 5, Semigroups.intSum)
      .findFirstOrError(), Matchers.equalTo(LazyEither.right(1)));
}

代码示例来源:origin: aol/cyclops

@Test
public void combineOneFirstOrError() {
  assertThat(ofWait(1)
      .combine((a, b) -> a < 5, Semigroups.intSum)
      .findFirstOrError(), Matchers.equalTo(LazyEither.right(1)));
}
@Test

代码示例来源:origin: aol/cyclops

private Either<Error,Vector<String>> loadContents(Vector<DataFileMetadata> files){
    /**
    return Spouts.from(Flux.from(files.stream())
          .flatMap(file->asyncWithRetry(1,file,exec),10))
          .reduceAll(Vector.<String>empty(), Vector::appendAll)
          .findFirstOrError()
          .mapLeft(t-> Error.LOADING_FAILED);
    **/
    return files.stream()
               .mergeMap(10,file->asyncWithRetry(1,file,exec))
               .reduceAll(Vector.<String>empty(), Vector::appendAll)
               .findFirstOrError()
               .mapLeft(t-> Error.LOADING_FAILED);

  }
}

代码示例来源:origin: com.oath.cyclops/cyclops-futurestream

@Override
default LazyEither<Throwable, U> findFirstOrError(){
  return stream().findFirstOrError();
}

相关文章

微信公众号

最新文章

更多

ReactiveSeq类方法