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

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

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

ReactiveSeq.takeOne介绍

[英]Lazy / reactive analogue of findFirst / findAny from JDK For push based reactive-streams (created via Spouts.XXX) data will be pushed to the returned Maybe on arrival. For pull based Streams (created via ReactiveSeq.XXX) the Stream will be executed when the Maybe is first accessed.
[中]JDK中基于推送的反应流(通过Spouts.XXX创建)的findFirst/findAny的惰性/反应性模拟数据将在到达时被推送到返回的数据库。对于基于pull的流(通过ReactiveSeq.XXX创建),将在首次访问Maybe时执行流。

代码示例

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

default Maybe<T> takeOne(){
  return stream().takeOne();
}
/**

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

@Override
public Option<T> last() {
  return stream().takeRight(1).takeOne();
}

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

@Override
public Option<V> get(int bitShiftDepth, int hash, K key) {
  if (this.hash == hash) {
    return bucket.stream().filter(t -> Objects.equals(key, t._1())).takeOne().map(Tuple2::_2);
  }
  return Option.none();
}

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

/**
 * Construct a Maybe  that contains a single value extracted from the supplied reactive-streams Publisher
 * <pre>
 * {@code
 *   ReactiveSeq<Integer> stream =  ReactiveSeq.of(1,2,3);
  Option<Integer> maybe = Option.fromPublisher(stream);
  //Option[1]
 *
 * }
 * </pre>
 *
 * @param pub Publisher to extract value from
 * @return Maybe populated with first value from Publisher (Option.zero if Publisher zero)
 */
public static <T> Option<T> fromPublisher(final Publisher<T> pub) {
  return Spouts.from(pub)
         .take(1)
         .takeOne()
         .toOption();
}

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

default Maybe<Long> indexOf(Predicate<? super T> pred){
 return stream().zipWithIndex()
         .filter(p->pred.test(p._1()))
         .takeOne()
         .map(v->v._2());
}
default Maybe<Long> lastIndexOf(Predicate<? super T> pred){

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

default Maybe<Long> lastIndexOf(Predicate<? super T> pred){
 return stream().zipWithIndex()
         .filter(p->pred.test(p._1()))
         .takeRight(1)
         .takeOne()
         .map(v->v._2());
}
default Maybe<Long> indexOfSlice(Iterable<? extends T> slice){

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

/**
 * Return the elementAt index or Optional.empty
 *
 * <pre>
 * {@code
 *     assertThat(ReactiveSeq.of(1,2,3,4,5).elementAt(2).getValue(),equalTo(3));
 * }
 * </pre>
 *
 * @param index
 *            to extract element from
 * @return elementAt index
 */
@Override
default Maybe<T> elementAt(final long index) {
  return this.zipWithIndex()
        .filter(t -> t._2() == index)
        .takeOne()
        .map(t -> t._1());
}

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

@Test
public void combineOne() {
  assertThat(ofWait(1)
      .combine((a, b) -> a < 5, Semigroups.intSum)
      .takeOne(), Matchers.equalTo(Maybe.of(1)));
}

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

@Test
public void combine() {
  assertThat(of(1, 2, 3, 4, 5, 6, 7, 8)
      .combine((a, b) -> a < 5, Semigroups.intSum)
      .takeOne(), Matchers.equalTo(Maybe.of(6)));
}

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

@Test
public void combineEmpty() {
  assertThat(this.<Integer>of()
      .combine((a, b) -> a < 5, Semigroups.intSum)
      .takeOne(), Matchers.equalTo(Maybe.nothing()));
}

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

@Test
public void combineTwo() {
    assertThat(ofWait(1, 2)
        .combine((a, b) -> a < 5, Semigroups.intSum)
        .takeOne(), Matchers.equalTo(Maybe.of(3)));
}

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

@Test
public void combineTwo() {
  assertThat(of(1, 2)
      .combine((a, b) -> a < 5, Semigroups.intSum)
      .takeOne(), Matchers.equalTo(Maybe.of(3)));
}

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

@Test
public void combine() {
  assertThat(ofWait(1, 2, 3, 4, 5, 6, 7, 8).combine((a, b) -> a < 5, Semigroups.intSum)
      .takeOne(), Matchers.equalTo(Maybe.of(6)));
}

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

@Test
public void combineOne() {
  assertThat(of(1)
      .combine((a, b) -> a < 5, Semigroups.intSum)
      .takeOne(), Matchers.equalTo(Maybe.of(1)));
}

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

@Test
public void takeOne(){
  assertThat(of()
          .takeOne().isPresent(),equalTo(false));
  assertThat(of(1,2,3)
             .takeOne().toOptional().get(),equalTo(1));
  assertThat(of(1,2,3)
             .takeOne().toOptional().get(),equalTo(1));
  assertThat(of(1,2,3)
             .elementAt(0).toOptional().get(),equalTo(1));
  assertThat(of(1,2,3)
             .elementAt(0l).toOptional().get(),equalTo(1));
  assertThat(of(1,2,3)
      .elementAt(1).toOptional().get(),equalTo(2));
  assertThat(of(1,2,3)
          .elementAt(1l).toOptional().get(),equalTo(2));
}

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

@Test
public void duplicateFindOne(){
  Tuple2<Integer, Long> v2 = of(1).duplicate()._1().zipWithIndex().takeOne().toOptional().get();
  assertThat(v2,equalTo(Tuple.tuple(1,0l)));
}
@Test

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

default Maybe<T> takeOne(){
  return stream().takeOne();
}
/**

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

@Override
public Option<T> last() {
  return stream().takeRight(1).takeOne();
}

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

@Override
public Option<V> get(int bitShiftDepth, int hash, K key) {
  if (this.hash == hash) {
    return bucket.stream().filter(t -> Objects.equals(key, t._1())).takeOne().map(Tuple2::_2);
  }
  return Option.none();
}

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

default Maybe<Long> lastIndexOf(Predicate<? super T> pred){
 return stream().zipWithIndex()
         .filter(p->pred.test(p._1()))
         .takeRight(1)
         .takeOne()
         .map(v->v._2());
}
default Maybe<Long> indexOfSlice(Iterable<? extends T> slice){

相关文章

微信公众号

最新文章

更多

ReactiveSeq类方法