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

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

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

ReactiveSeq.reduce介绍

暂无

代码示例

代码示例来源:origin: aol/micro-server

@GET
@Produces("text/plain")
@Path("/rest-calls")
public String restCallResult(){
  
  return simpleReact
    .fromStream(urls.stream()
        .map(it ->  template.getForEntity(it,String.class)))
    .then(it -> it.getBody())
    .then(it -> "*"+it)
    .peek(loadedAndModified -> System.out.println(loadedAndModified))
    .block().stream().reduce("", (acc,next) -> acc+"-"+next);
  
}

代码示例来源:origin: aol/micro-server

@GET
@Produces("text/plain")
@Path("/rest-calls")
public String restCallResult(){
  
  return simpleReact
    .fromStream(urls.stream()
        .map(it ->  template.getForEntity(it,String.class)))
    .then(it -> it.getBody())
    .then(it -> "*"+it)
    .peek(loadedAndModified -> System.out.println(loadedAndModified))
    .block().stream().reduce("", (acc,next) -> acc+"-"+next);
  
}

代码示例来源:origin: aol/micro-server

@GET
@Produces("text/plain")
@Path("/rest-calls")
public String restCallResult(){
  
  return FutureStream.builder().fromIterable(urls)
        .map(it ->template.get(it))
        .then(it -> "*"+it)
        .peek(loadedAndModified -> System.out.println(loadedAndModified))
        .block().stream().reduce("", (acc,next) -> acc+"-"+next);
  
}

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

default <A> T foldMap(final Publisher<A> toFoldMap, Function<? super A, ? extends T> mapFn){
  ReactiveSeq<T> toReduce = Spouts.from(toFoldMap).map(mapFn);
  return toReduce.reduce(zero(),this);
}
default <A> T foldMap(final Stream<A> toFoldMap, Function<? super A, ? extends T> mapFn){

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

default <A> T foldMap(final Iterable<A> toFoldMap, Function<? super A, ? extends T> mapFn){
  ReactiveSeq<T> toReduce = ReactiveSeq.fromIterable(toFoldMap).map(mapFn);
  return toReduce.reduce(zero(),this);
}
default <A> T foldMap(final ReactiveSeq<A> toFoldMap, Function<? super A, ? extends T> mapFn){

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

public static  <T> Optional<ReactiveSeq<T>> sequence(ReactiveSeq<? extends Optional<T>> stream) {
 Optional<ReactiveSeq<T>> identity = Optional.of(ReactiveSeq.empty());
 BiFunction<Optional<ReactiveSeq<T>>,Optional<T>,Optional<ReactiveSeq<T>>> combineToStream = (acc,next) ->zip(acc,next,(a,b)->a.append(b));
 BinaryOperator<Optional<ReactiveSeq<T>>> combineStreams = (a,b)-> zip(a,b,(z1,z2)->z1.appendStream(z2));
 return stream.reduce(identity,combineToStream,combineStreams);
}
public static <T,R> Optional<ReactiveSeq<R>> traverse(Function<? super T,? extends R> fn,ReactiveSeq<Optional<T>> stream) {

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

@Test
public void testFoldLeft() {
  for(int i=0;i<100;i++){
    Supplier<ReactiveSeq<String>> s = () -> of("a", "b", "c");
    assertTrue(s.get().reduce("", String::concat).contains("a"));
    assertTrue(s.get().reduce("", String::concat).contains("b"));
    assertTrue(s.get().reduce("", String::concat).contains("c"));
    assertEquals(3, (int) s.get().map(str->str.length()).foldLeft(0, (u, t) -> u + t));
    assertEquals(3, (int) s.get().map(str->str.length()).foldRight(0, (t, u) -> u + t));
  }
}

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

@Test
public void testFoldLeft() {
  for(int i=0;i<100;i++){
    Supplier<ReactiveSeq<String>> s = () -> of("a", "b", "c");
    assertTrue(s.get().reduce("", String::concat).contains("a"));
    assertTrue(s.get().reduce("", String::concat).contains("b"));
    assertTrue(s.get().reduce("", String::concat).contains("c"));
    assertEquals(3, (int) s.get().map(str->str.length()).foldLeft(0, (u, t) -> u + t));
    assertEquals(3, (int) s.get().map(str->str.length()).foldRight(0, (t, u) -> u + t));
  }
}

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

@Test
public void testMapReduce(){
  assertThat(of(1,2,3,4,5).map(it -> it*100).stream().reduce( (acc,next) -> acc+next).get(),is(1500));
}
@Test

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

public static  <L1,L2,L3,L4,T> LazyEither5<L1, L2, L3, L4,ReactiveSeq<T>> sequence(ReactiveSeq<? extends LazyEither5<L1, L2, L3, L4, T>> stream) {
 LazyEither5<L1, L2, L3, L4, ReactiveSeq<T>> identity = right(ReactiveSeq.empty());
 BiFunction<LazyEither5<L1, L2, L3, L4, ReactiveSeq<T>>,LazyEither5<L1, L2, L3, L4, T>,LazyEither5<L1, L2, L3, L4,ReactiveSeq<T>>> combineToStream = (acc,next) ->acc.zip(next,(a,b)->a.append(b));
 BinaryOperator<LazyEither5<L1, L2, L3, L4,ReactiveSeq<T>>> combineStreams = (a,b)-> a.zip(b,(z1,z2)->z1.appendStream(z2));
 return stream.reduce(identity,combineToStream,combineStreams);
}
public static <L1,L2,L3,L4,T,R> LazyEither5<L1, L2, L3, L4, ReactiveSeq<R>> traverse(Function<? super T,? extends R> fn,ReactiveSeq<LazyEither5<L1, L2, L3,L4,T>> stream) {

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

public static  <T> Eval<ReactiveSeq<T>> sequence(ReactiveSeq<? extends Eval<T>> stream) {
 Eval<ReactiveSeq<T>> identity = Eval.now(ReactiveSeq.empty());
 BiFunction<Eval<ReactiveSeq<T>>,Eval<T>,Eval<ReactiveSeq<T>>> combineToStream = (acc, next) ->acc.zipWith(next,(a, b)->a.append(b));
 BinaryOperator<Eval<ReactiveSeq<T>>> combineStreams = (a, b)-> a.zipWith(b,(z1, z2)->z1.appendStream(z2));
 return stream.reduce(identity,combineToStream,combineStreams);
}
public static <T,R> Eval<ReactiveSeq<R>> traverse(Function<? super T, ? extends R> fn, ReactiveSeq<Eval<T>> stream) {

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

public static  <T> Option<ReactiveSeq<T>> sequence(ReactiveSeq<? extends Option<T>> stream) {
 Option<ReactiveSeq<T>> identity = Option.some(ReactiveSeq.empty());
 BiFunction<Option<ReactiveSeq<T>>,Option<T>,Option<ReactiveSeq<T>>> combineToStream = (acc,next) ->acc.zip(next,(a,b)->a.append(b));
 BinaryOperator<Option<ReactiveSeq<T>>> combineStreams = (a,b)-> a.zip(b,(z1,z2)->z1.appendStream(z2));
 return stream.reduce(identity,combineToStream,combineStreams);
}
public static <T,R> Option<ReactiveSeq<R>> traverse(Function<? super T,? extends R> fn,ReactiveSeq<Option<T>> stream) {

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

public static  <L1,L2,T> LazyEither3<L1,L2,ReactiveSeq<T>> sequence(ReactiveSeq<? extends LazyEither3<L1,L2,T>> stream) {
 LazyEither3<L1,L2, ReactiveSeq<T>> identity = right(ReactiveSeq.empty());
 BiFunction<LazyEither3<L1,L2,ReactiveSeq<T>>,LazyEither3<L1,L2,T>,LazyEither3<L1,L2,ReactiveSeq<T>>> combineToStream = (acc,next) ->acc.zip(next,(a,b)->a.append(b));
 BinaryOperator<LazyEither3<L1,L2,ReactiveSeq<T>>> combineStreams = (a,b)-> a.zip(b,(z1,z2)->z1.appendStream(z2));
 return stream.reduce(identity,combineToStream,combineStreams);
}
public static <L1,L2,T,R> LazyEither3<L1,L2,ReactiveSeq<R>> traverse(Function<? super T,? extends R> fn,ReactiveSeq<LazyEither3<L1,L2,T>> stream) {

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

@Test
public void testMapReduceCombiner(){
  assertThat(of(1,2,3,4,5).map(it -> it*100).stream().reduce( 0,
      (acc, next) -> acc+next,
      Integer::sum),is(1500));
}
/**

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

public static  <L1,L2,L3,T> LazyEither4<L1, L2, L3, ReactiveSeq<T>> sequence(ReactiveSeq<? extends LazyEither4<L1, L2, L3, T>> stream) {
 LazyEither4<L1, L2, L3, ReactiveSeq<T>> identity = right(ReactiveSeq.empty());
 BiFunction<LazyEither4<L1, L2, L3, ReactiveSeq<T>>,LazyEither4<L1, L2, L3, T>,LazyEither4<L1, L2, L3,ReactiveSeq<T>>> combineToStream = (acc,next) ->acc.zip(next,(a,b)->a.append(b));
 BinaryOperator<LazyEither4<L1, L2, L3,ReactiveSeq<T>>> combineStreams = (a,b)-> a.zip(b,(z1,z2)->z1.appendStream(z2));
 return stream.reduce(identity,combineToStream,combineStreams);
}
public static <L1,L2,L3,T,R> LazyEither4<L1, L2, L3, ReactiveSeq<R>> traverse(Function<? super T,? extends R> fn,ReactiveSeq<LazyEither4<L1, L2, L3,T>> stream) {

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

@Test
public void testMapReduce(){
  assertThat(of(1,2,3,4,5).map(it -> it*100).reduce( (acc,next) -> acc+next).get(),equalTo(1500));
}
@Test

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

@Test
public void testMapReduce(){
  assertThat(of(1,2,3,4,5).map(it -> it*100).reduce( (acc,next) -> acc+next).get(),equalTo(1500));
}
@Test

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

public static  <L,T> LazyEither<L,ReactiveSeq<T>> sequence(ReactiveSeq<? extends LazyEither<L,T>> stream) {
 LazyEither<L, ReactiveSeq<T>> identity = right(ReactiveSeq.empty());
 BiFunction<LazyEither<L,ReactiveSeq<T>>,LazyEither<L,T>,LazyEither<L,ReactiveSeq<T>>> combineToStream = (acc,next) ->acc.zip(next,(a,b)->a.append(b));
 BinaryOperator<LazyEither<L,ReactiveSeq<T>>> combineStreams = (a,b)-> a.zip(b,(z1,z2)->z1.appendStream(z2));
 return stream.reduce(identity,combineToStream,combineStreams);
}
public static <L,T,R> LazyEither<L,ReactiveSeq<R>> traverse(Function<? super T,? extends R> fn,ReactiveSeq<LazyEither<L,T>> stream) {

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

@Test
public void testMapReduce(){
  assertThat(of(1,2,3,4,5).map(it -> it*100).reduce( (acc,next) -> acc+next).get(),equalTo(1500));
}
@Test

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

@Test
public void testMapReduceCombiner(){
  assertThat(of(1,2,3,4,5).map(it -> it*100).reduce( 0,
      (acc, next) -> acc+next,
      Integer::sum),equalTo(1500));
}
@Test

相关文章

微信公众号

最新文章

更多

ReactiveSeq类方法