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

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

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

ReactiveSeq.partition介绍

[英]Partition a Stream into two one a per element basis, based on predicate's boolean value

ReactiveSeq.of(1, 2, 3, 4, 5, 6).partition(i -> i % 2 != 0)

[中]根据谓词的布尔值将流分成两个,每个元素一个

代码示例

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

@Test
public void testPartitionSequence() {
  Supplier<ReactiveSeq<Integer>> s = () -> of(1, 2, 3, 4, 5, 6);
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 != 0)._1().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 != 0)._2().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 == 0)._1().toList());
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 == 0)._2().toList());
  assertEquals(asList(1, 2, 3), s.get().partition(i -> i <= 3)._1().toList());
  assertEquals(asList(4, 5, 6), s.get().partition(i -> i <= 3)._2().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> true)._1().toList());
  assertEquals(asList(), s.get().partition(i -> true)._2().toList());
  assertEquals(asList(), s.get().partition(i -> false)._1().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> false)._2().toList());
}

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

@Test
public void testPartition() {
  Supplier<ReactiveSeq<Integer>> s = () -> Spouts.of(1, 2, 3, 4, 5, 6);
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 != 0)._1().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 != 0)._2().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 == 0)._1().toList());
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 == 0)._2().toList());
  assertEquals(asList(1, 2, 3), s.get().partition(i -> i <= 3)._1().toList());
  assertEquals(asList(4, 5, 6), s.get().partition(i -> i <= 3)._2().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> true)._1().toList());
  assertEquals(asList(), s.get().partition(i -> true)._2().toList());
  assertEquals(asList(), s.get().partition(i -> false)._1().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> false)._2().toList());
}
@Test

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

@Test
public void testPartitionSequence() {
  Supplier<ReactiveSeq<Integer>> s = () -> of(1, 2, 3, 4, 5, 6);
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 != 0)._1().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 != 0)._2().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 == 0)._1().toList());
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 == 0)._2().toList());
  assertEquals(asList(1, 2, 3), s.get().partition(i -> i <= 3)._1().toList());
  assertEquals(asList(4, 5, 6), s.get().partition(i -> i <= 3)._2().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> true)._1().toList());
  assertEquals(asList(), s.get().partition(i -> true)._2().toList());
  assertEquals(asList(), s.get().partition(i -> false)._1().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> false)._2().toList());
}

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

@Test
public void testPartitionSequence() {
  Supplier<ReactiveSeq<Integer>> s = () -> Spouts.of(1, 2, 3, 4, 5, 6);
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 != 0)._1().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 != 0)._2().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 == 0)._1().toList());
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 == 0)._2().toList());
  assertEquals(asList(1, 2, 3), s.get().partition(i -> i <= 3)._1().toList());
  assertEquals(asList(4, 5, 6), s.get().partition(i -> i <= 3)._2().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> true)._1().toList());
  assertEquals(asList(), s.get().partition(i -> true)._2().toList());
  assertEquals(asList(), s.get().partition(i -> false)._1().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> false)._2().toList());
}

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

@Test
public void testPartitionSequence() {
  Supplier<ReactiveSeq<Integer>> s = () -> Spouts.of(1, 2, 3, 4, 5, 6);
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 != 0)._1().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 != 0)._2().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 == 0)._1().toList());
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 == 0)._2().toList());
  assertEquals(asList(1, 2, 3), s.get().partition(i -> i <= 3)._1().toList());
  assertEquals(asList(4, 5, 6), s.get().partition(i -> i <= 3)._2().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> true)._1().toList());
  assertEquals(asList(), s.get().partition(i -> true)._2().toList());
  assertEquals(asList(), s.get().partition(i -> false)._1().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> false)._2().toList());
}

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

@Test
public void testPartition() {
  Supplier<ReactiveSeq<Integer>> s = () -> of(1, 2, 3, 4, 5, 6);
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 != 0)._1().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 != 0)._2().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 == 0)._1().toList());
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 == 0)._2().toList());
  assertEquals(asList(1, 2, 3), s.get().partition(i -> i <= 3)._1().toList());
  assertEquals(asList(4, 5, 6), s.get().partition(i -> i <= 3)._2().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> true)._1().toList());
  assertEquals(asList(), s.get().partition(i -> true)._2().toList());
  assertEquals(asList(), s.get().partition(i -> false)._1().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> false)._2().toList());
}
@Test

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

/**
 * Partition a Stream into two one a per element basis, based on predicate's boolean value
 * <pre>
 * {@code
 *  Streamable.of(1, 2, 3, 4, 5, 6).partition(i -> i % 2 != 0)
 *
 *  //Streamable[1,3,5], Streamable[2,4,6]
 * }
 *
 * </pre>
 */
default Tuple2<Streamable<T>, Streamable<T>> partition(final Predicate<T> splitter) {
  return this.stream().partition(splitter)
            .map1(s -> fromStream(s))
            .map2(s -> fromStream(s));
}

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

@Test
public void testPartitionSequence() {
  Supplier<ReactiveSeq<Integer>> s = () -> of(1, 2, 3, 4, 5, 6);
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 != 0)._1().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 != 0)._2().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 == 0)._1().toList());
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 == 0)._2().toList());
  assertEquals(asList(1, 2, 3), s.get().partition(i -> i <= 3)._1().toList());
  assertEquals(asList(4, 5, 6), s.get().partition(i -> i <= 3)._2().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> true)._1().toList());
  assertEquals(asList(), s.get().partition(i -> true)._2().toList());
  assertEquals(asList(), s.get().partition(i -> false)._1().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> false)._2().toList());
}

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

@Test
public void testPartitionSequence() {
  Supplier<ReactiveSeq<Integer>> s = () -> ReactiveSeq.of(1, 2, 3, 4, 5, 6);
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 != 0)._1().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 != 0)._2().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 == 0)._1().toList());
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 == 0)._2().toList());
  assertEquals(asList(1, 2, 3), s.get().partition(i -> i <= 3)._1().toList());
  assertEquals(asList(4, 5, 6), s.get().partition(i -> i <= 3)._2().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> true)._1().toList());
  assertEquals(asList(), s.get().partition(i -> true)._2().toList());
  assertEquals(asList(), s.get().partition(i -> false)._1().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> false)._2().toList());
}

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

@Test
public void testPartition() {
  Supplier<ReactiveSeq<Integer>> s = () -> of(1, 2, 3, 4, 5, 6);
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 != 0)._1().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 != 0)._2().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 == 0)._1().toList());
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 == 0)._2().toList());
  assertEquals(asList(1, 2, 3), s.get().partition(i -> i <= 3)._1().toList());
  assertEquals(asList(4, 5, 6), s.get().partition(i -> i <= 3)._2().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> true)._1().toList());
  assertEquals(asList(), s.get().partition(i -> true)._2().toList());
  assertEquals(asList(), s.get().partition(i -> false)._1().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> false)._2().toList());
}
@Test

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

@Test
public void testPartition() {
  Supplier<ReactiveSeq<Integer>> s = () -> Spouts.of(1, 2, 3, 4, 5, 6);
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 != 0)._1().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 != 0)._2().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 == 0)._1().toList());
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 == 0)._2().toList());
  assertEquals(asList(1, 2, 3), s.get().partition(i -> i <= 3)._1().toList());
  assertEquals(asList(4, 5, 6), s.get().partition(i -> i <= 3)._2().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> true)._1().toList());
  assertEquals(asList(), s.get().partition(i -> true)._2().toList());
  assertEquals(asList(), s.get().partition(i -> false)._1().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> false)._2().toList());
}
@Test

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

@Test
public void testPartition() {
  Supplier<ReactiveSeq<Integer>> s = () -> of(1, 2, 3, 4, 5, 6);
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 != 0)._1().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 != 0)._2().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 == 0)._1().toList());
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 == 0)._2().toList());
  assertEquals(asList(1, 2, 3), s.get().partition(i -> i <= 3)._1().toList());
  assertEquals(asList(4, 5, 6), s.get().partition(i -> i <= 3)._2().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> true)._1().toList());
  assertEquals(asList(), s.get().partition(i -> true)._2().toList());
  assertEquals(asList(), s.get().partition(i -> false)._1().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> false)._2().toList());
}
@Test

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

@Test
public void testPartition() {
  Supplier<ReactiveSeq<Integer>> s = () -> ReactiveSeq.of(1, 2, 3, 4, 5, 6);
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 != 0)._1().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 != 0)._2().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 == 0)._1().toList());
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 == 0)._2().toList());
  assertEquals(asList(1, 2, 3), s.get().partition(i -> i <= 3)._1().toList());
  assertEquals(asList(4, 5, 6), s.get().partition(i -> i <= 3)._2().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> true)._1().toList());
  assertEquals(asList(), s.get().partition(i -> true)._2().toList());
  assertEquals(asList(), s.get().partition(i -> false)._1().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> false)._2().toList());
}
@Test

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

@Test
public void testPartition() {
  Supplier<ReactiveSeq<Integer>> s = () -> of(1, 2, 3, 4, 5, 6);
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 != 0)._1().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 != 0)._2().toList());
  assertEquals(asList(2, 4, 6), s.get().partition(i -> i % 2 == 0)._1().toList());
  assertEquals(asList(1, 3, 5), s.get().partition(i -> i % 2 == 0)._2().toList());
  assertEquals(asList(1, 2, 3), s.get().partition(i -> i <= 3)._1().toList());
  assertEquals(asList(4, 5, 6), s.get().partition(i -> i <= 3)._2().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().partition(i -> true)._1().toList());
  assertEquals(asList(), s.get().partition(i -> true)._2().toList());
  assertEquals(asList(), s.get().partition(i -> false)._1().toList());
  assertEquals(asList(1, 2, 3, 4, 5, 6), s.get().splitBy(i -> false)._2().toList());
}

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

/**
 * Partition a stream in two given a predicate. Two LazyFutureStreams are
 * returned but Seq interface specifies return type is Seq. See partitionFutureStream to
 * see an alternative which returns FutureStream
 *
 * <code>
 *
 * // tuple((1, 3, 5), (2, 4, 6))
 *
 * FutureStream.of(1, 2, 3, 4, 5,6).partition(i -&gt; i % 2 != 0)
 *
 * </code>
 *
 */
@Override
default Tuple2<ReactiveSeq<U>, ReactiveSeq<U>> partition(final Predicate<? super U> predicate) {
  return ReactiveSeq.oneShotStream(stream())
      .partition(predicate);
}

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

/**
 * Partition a Stream into two one a per element basis, based on predicate's boolean value
 * <pre>
 * {@code
 *  Streamable.of(1, 2, 3, 4, 5, 6).partition(i -> i % 2 != 0)
 *
 *  //Streamable[1,3,5], Streamable[2,4,6]
 * }
 *
 * </pre>
 */
default Tuple2<Streamable<T>, Streamable<T>> partition(final Predicate<T> splitter) {
  return this.stream().partition(splitter)
            .map1(s -> fromStream(s))
            .map2(s -> fromStream(s));
}

相关文章

微信公众号

最新文章

更多

ReactiveSeq类方法