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

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

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

ReactiveSeq.zip介绍

[英]Add an index to the current Stream

assertEquals(asList(new Tuple2("a", 0L), new Tuple2("b", 1L)), of("a", "b").zipWithIndex().toList());

[中]向当前流添加索引

assertEquals(asList(new Tuple2("a", 0L), new Tuple2("b", 1L)), of("a", "b").zipWithIndex().toList());

代码示例

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

@Override
public <T2, T3, T4> ReactiveSeq<Tuple4<T, T2, T3, T4>> zip4(Iterable<? extends T2> second, Iterable<? extends T3> third, Iterable<? extends T4> fourth) {
  return zip(second, Tuple::tuple).zip(third, (a, b) -> Tuple.tuple(a._1(), a._2(), b))
      .zip(fourth, (a, b) -> (Tuple4<T, T2, T3, T4>) Tuple.tuple(a._1(), a._2(), a._3(), b));
}

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

@Test
public void testZipWithIndex() {
  assertEquals(asList(), of().zipWithIndex().toList());
  assertEquals(asList(tuple("a", 0L)), of("a").zip(of(0L)).toList());
 }

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

@Test
public void shouldReturnEmptySeqWhenZipEmptyWithNonEmpty() throws Exception {
  final ReactiveSeq<Integer> zipped = empty.zip(nonEmpty, (a, b) -> a + b);
  assertTrue(zipped.collect(Collectors.toList()).isEmpty());
}

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

@Test
public void shouldReturnEmptySeqWhenZipNonEmptyWithEmpty() throws Exception {
  final ReactiveSeq<Integer> zipped = nonEmpty.zip(empty, (a, b) -> a + b);
  assertTrue(zipped.collect(Collectors.toList()).isEmpty());
}

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

@Test
public void zip2of() {
  List<Tuple2<Integer, Integer>> list = of(1, 2, 3, 4, 5, 6).zip(of(100, 200, 300, 400)).peek(it -> System.out.println(it)).collect(Collectors.toList());
  List<Integer> right = list.stream().map(t -> t._2()).collect(Collectors.toList());
  assertThat(right, hasItem(100));
  assertThat(right, hasItem(200));
  assertThat(right, hasItem(300));
  assertThat(right, hasItem(400));
  List<Integer> left = list.stream().map(t -> t._1()).collect(Collectors.toList());
  assertThat(Arrays.asList(1, 2, 3, 4, 5, 6), hasItem(left.get(0)));
}

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

@Test
public void zipEmpty() throws Exception {
  final ReactiveSeq<Integer> zipped = empty.zip(this.<Integer>of(), (a, b) -> a + b);
  assertTrue(zipped.collect(Collectors.toList()).isEmpty());
}

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

@Test
public void zipInOrder(){
  List<Tuple2<Integer,Integer>> list =  of(1,2,3,4,5,6)
                        .zip( of(100,200,300,400))
                        .collect(Collectors.toList());
  assertThat(asList(1,2,3,4,5,6),hasItem(list.get(0)._1()));
  assertThat(asList(100,200,300,400),hasItem(list.get(0)._2()));
}

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

@Test
public void shouldTrimSecondFixedSeqIfLongerSequence() throws Exception {
  final ReactiveSeq<String> first = of("A", "B", "C");
  final ReactiveSeq<Integer> second = of(1, 2, 3, 4);
  final ReactiveSeq<String> zipped = first.zip(second, (a, b) -> a + b);
  assertThat(zipped.collect(Collectors.toList()).size(),is(3));
}

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

@Test
public void shouldTrimFirstFixedSeqIfLonger() throws Exception {
  final ReactiveSeq<String> first = of("A", "B", "C","D");
  final ReactiveSeq<Integer> second = of(1, 2, 3);
  final ReactiveSeq<String> zipped = first.zip(second, (a, b) -> a + b);
  assertThat(zipped.collect(Collectors.toList()).size(),equalTo(3));
}

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

@Test
public void shouldTrimFirstFixedSeqIfLongerSequence() throws Exception {
  final ReactiveSeq<String> first = of("A", "B", "C","D");
  final ReactiveSeq<Integer> second = of(1, 2, 3);
  final ReactiveSeq<String> zipped = first.zip(second, (a, b) -> a + b);
  assertThat(zipped.collect(Collectors.toList()).size(),equalTo(3));
}

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

@Test
public void shouldTrimFirstFixedSeqIfLonger() throws Exception {
  final ReactiveSeq<String> first = of("A", "B", "C","D");
  final ReactiveSeq<Integer> second = of(1, 2, 3);
  final ReactiveSeq<String> zipped = first.zip(second, (a, b) -> a + b);
  assertThat(zipped.collect(Collectors.toList()).size(),equalTo(3));
}

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

@Test
public void testZipDifferingLength() {
  List<Tuple2<Integer, String>> list = of(1, 2).zip(of("a", "b", "c", "d")).toList();
  assertEquals(2, list.size());
  assertTrue(asList(1, 2).contains(list.get(0)._1()));
  assertTrue("" + list.get(1)._2(), asList(1, 2).contains(list.get(1)._1()));
  assertTrue(asList("a", "b", "c", "d").contains(list.get(0)._2()));
  assertTrue(asList("a", "b", "c", "d").contains(list.get(1)._2()));
}

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

@Test
public void testZipDifferingLengthStream() {
  List<Tuple2<Integer, String>> list = of(1, 2).zip(of("a", "b", "c", "d")).toList();
  assertEquals(2, list.size());
  assertTrue(asList(1, 2).contains(list.get(0)._1()));
  assertTrue("" + list.get(1)._2(), asList(1, 2).contains(list.get(1)._1()));
  assertTrue(asList("a", "b", "c", "d").contains(list.get(0)._2()));
  assertTrue(asList("a", "b", "c", "d").contains(list.get(1)._2()));
}

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

@Test
public void shouldZipTwoFiniteSequencesOfSameSize() throws Exception {
  final ReactiveSeq<String> first = of("A", "B", "C");
  final ReactiveSeq<Integer> second = of(1, 2, 3);
  final ReactiveSeq<String> zipped = first.zip(second, (a, b) -> a + b);
  assertThat(zipped.collect(Collectors.toList()).size(),is(3));
}

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

@Test
public void testZipDifferingLengthStream() {
  List<Tuple2<Integer, String>> list = of(1, 2).zip(of("a", "b", "c", "d")).toList();
  assertEquals(2, list.size());
  assertTrue(asList(1, 2).contains(list.get(0)._1()));
  assertTrue("" + list.get(1)._2(), asList(1, 2).contains(list.get(1)._1()));
  assertTrue(asList("a", "b", "c", "d").contains(list.get(0)._2()));
  assertTrue(asList("a", "b", "c", "d").contains(list.get(1)._2()));
}

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

@Test
public void zipUnevenLeft(){
  for(int i=0;i<100;i++) {
    System.out.println(i);
    assertEquals(asList(tuple("a", 0L)), of("a", "b").zip(of(0L)).toList());
    assertEquals(asList(tuple("a", 0L), tuple("b", 1L)), of("a", "b", "c").zip(of(0L, 1L)).toList());
    assertEquals(asList(tuple("a", 0L), tuple("b", 1L)), of("a", "b", "c").zip(of(0L, 1L)).collect(Collectors.toList()));
    assertEquals(asList(tuple("a", 0L), tuple("b", 1L)), of("a", "b", "c", "d").zip(of(0L, 1L)).toList());
  }
}

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

@Test
public void simpleZip(){
  of(1,2,3)
      .zip(of(100,200))
      .forEach(System.out::println);
}
@Test

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

@Test
public void zipUnevenRight(){
  for(int i=0;i<100;i++) {
    System.out.println(i);
    assertEquals(asList("a"), of("a").toList());
    assertEquals(asList(tuple("a", 0L)), of("a").zip(of(0L, 1L, 2L)).toList());
    assertEquals(asList(tuple("a", 0L), tuple("b", 1L)), of("a", "b").zip(of(0L, 1L, 2L, 3L)).toList());
    assertEquals(asList(tuple("a", 0L), tuple("b", 1L)), of("a", "b").zip(of(0L, 1L, 2L, 3L, 4L)).toList());
    assertEquals(asList(tuple("a", 0L), tuple("b", 1L)), of("a", "b").zip(of(0L, 1L, 2L, 3L, 4L, 5L)).toList());
    assertEquals(asList(tuple(0L, "a"), tuple(1L, "b")), of(0L, 1L).zip(of("a", "b", "c", "d")).toList());
  }
}

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

@Test
public void unevenTest(){
  assertEquals(asList(tuple("a", 0L)), of("a","b","c").zip(of(0L)).toList());
}
@Test

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

@Test
public void unevenTest(){
  assertEquals(asList(tuple("a", 0L)), of("a","b","c").zip(of(0L)).to(Streamable::fromStream).toList());
}
@Test

相关文章

微信公众号

最新文章

更多

ReactiveSeq类方法