本文整理了Java中cyclops.reactive.ReactiveSeq.to
方法的一些代码示例,展示了ReactiveSeq.to
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ReactiveSeq.to
方法的具体详情如下:
包路径:cyclops.reactive.ReactiveSeq
类名称:ReactiveSeq
方法名:to
暂无
代码示例来源:origin: aol/micro-server
private ListX<Plugin> load(){
return ReactiveSeq.fromIterable(ServiceLoader.load(Plugin.class)).to(ListX::fromIterable);
}
}
代码示例来源:origin: aol/cyclops
@Test
public void multipathsLongs() {
ReactiveSeq<Long> list = ReactiveSeq.ofLongs(1, 2, 3);
ReactiveSeq<Long> by10 = list.map(i -> i * 10);
ReactiveSeq<Long> plus2 = list.map(i -> i + 2);
ReactiveSeq<Long> by10Plus2 = by10.to(mapLongs(i -> i + 2));
assertThat(by10.toList(), equalTo(Arrays.asList(10l, 20l, 30l)));
assertThat(plus2.toList(), equalTo(Arrays.asList(3l, 4l, 5l)));
assertThat(by10Plus2.toList(), equalTo(Arrays.asList(12l, 22l, 32l)));
}
@Test
代码示例来源:origin: aol/micro-server
default List<Class<?>> getDefaultResources() {
return PluginLoader.INSTANCE.plugins.get()
.stream()
.concatMap(Plugin::jaxRsResources)
.to(ListX::fromIterable);
}
代码示例来源:origin: aol/cyclops
@Test
public void coflatMap(){
assertThat(of("a", "b", "c").coflatMap(s->s.toList()).to(Streamable::fromStream).toList(),equalTo(
Arrays.asList(Arrays.asList("a","b","c"))));
}
@Test
代码示例来源:origin: aol/micro-server
default List<String> getDefaultJaxRsPackages() {
return PluginLoader.INSTANCE.plugins.get()
.stream()
.filter(module -> module.servletContextListeners() != null)
.concatMap(Plugin::jaxRsPackages)
.to(ListX::fromIterable);
}
代码示例来源:origin: aol/cyclops
@Test
public void concurrentLazyStreamable(){
Streamable<Integer> repeat = Spouts.of(1,2,3,4,5,6)
.map(i->i*2).to()
.streamable();
assertThat(repeat.stream().toList(),equalTo(Arrays.asList(2,4,6,8,10,12)));
assertThat(repeat.stream().toList(),equalTo(Arrays.asList(2,4,6,8,10,12)));
}
@Test
代码示例来源:origin: aol/micro-server
default List<ServletRequestListener> getRequestListeners(ServerData data) {
return PluginLoader.INSTANCE.plugins.get()
.stream()
.filter(module -> module.servletRequestListeners() != null)
.concatMap(Plugin::servletRequestListeners)
.map(fn -> fn.apply(data))
.to(ListX::fromIterable);
}
代码示例来源:origin: aol/micro-server
default List<ServletContextListener> getListeners(ServerData data) {
List<ServletContextListener> list = new ArrayList<>();
if (data.getRootContext() instanceof WebApplicationContext) {
list.add(new ContextLoaderListener(
(WebApplicationContext) data.getRootContext()));
}
ListX<Plugin> modules = PluginLoader.INSTANCE.plugins.get();
ListX<ServletContextListener> listeners = modules.stream()
.filter(module -> module.servletContextListeners() != null)
.concatMap(Plugin::servletContextListeners)
.map(fn -> fn.apply(data))
.to(ListX::fromIterable);
return listeners.plusAll(list);
}
代码示例来源:origin: aol/cyclops
@Test
public void collect(){
assertThat(of(1,2,3,4,5).to(Streamable::fromStream).collect(Collectors.toList()).size(),equalTo(5));
assertThat(of(1,1,1,2).to(Streamable::fromStream).collect(Collectors.toSet()).size(),equalTo(2));
}
@Test
代码示例来源:origin: aol/cyclops
@Test
public void testLazyCollection(){
Collection<Integer> col = Spouts.of(1,2,3,4,5)
.peek(System.out::println).to()
.lazyCollection();
System.out.println("takeOne!");
col.forEach(System.out::println);
assertThat(col.size(),equalTo(5));
}
代码示例来源:origin: aol/cyclops
@Test
public void testLimitLast1(){
assertThat(Spouts.of(1,2,3,4,5)
.takeRight(1)
.to(Streamable::fromStream).collect(Collectors.toList()),equalTo(Arrays.asList(5)));
}
@Test
代码示例来源:origin: aol/cyclops
@Test
public void flatMapMaybe(){
assertThat(Spouts.of(1,2,3,null).concatMap(Maybe::ofNullable)
.to(Streamable::fromStream).collect(Collectors.toList()),
equalTo(Arrays.asList(1,2,3)));
}
@Test
代码示例来源:origin: aol/cyclops
@Test
public void testMap(){
assertThat(of(1).map(it->it+100).to(Streamable::fromStream).collect(Collectors.toList()).get(0),equalTo(101));
}
Object val;
代码示例来源:origin: aol/cyclops
@Test
public void batchWhile(){
assertThat(Spouts.of(1,2,3,4,5,6)
.groupedWhile(i->i%3!=0)
.to(Streamable::fromStream).toList()
.size(),equalTo(2));
assertThat(Spouts.of(1,2,3,4,5,6)
.groupedWhile(i->i%3!=0)
.to(Streamable::fromStream).toList(),equalTo(Arrays.asList(Vector.of(1,2,3),Vector.of(4,5,6))));
}
@Test
代码示例来源:origin: aol/cyclops
@Test
public void judder(){
SimpleTimer timer = new SimpleTimer();
assertThat(of(1,2,3,4,5,6).jitter(10000).to(Streamable::fromStream).collect(Collectors.toList()).size(),is(6));
assertThat(timer.getElapsedNanoseconds(),greaterThan(20000l));
}
@Test
代码示例来源:origin: aol/cyclops
@Test
public void batchBySizeSet(){
System.out.println("List = " + of(1,1,1,1,1,1).grouped(3,()->TreeSet.empty()).to(Streamable::fromStream).toList());
assertThat(of(1,1,1,1,1,1).grouped(3,()-> TreeSet.empty()).to(Streamable::fromStream).toList().get(0).size(),is(1));
assertThat(of(1,1,1,1,1,1).grouped(3,()->TreeSet.empty()).to(Streamable::fromStream).toList().size(),is(1));
}
@Test
代码示例来源:origin: aol/cyclops
@Test
public void batchBySizeSetEmpty(){
assertThat(Spouts.<Integer>of().grouped(3,()->TreeSet.empty()).to(Streamable::fromStream).toList().size(),is(0));
}
@Test
代码示例来源:origin: aol/cyclops
@Test
public void testIterable() {
List<Integer> list = of(1, 2, 3).to().collection(LinkedList::new);
for (Integer i :of(1, 2, 3)) {
assertThat(list,hasItem(i));
}
}
代码示例来源:origin: aol/cyclops
@Test
public void batchBySizeAndTimeSizeCollection(){
assertThat(of(1,2,3,4,5,6)
.groupedBySizeAndTime(3, 10, TimeUnit.SECONDS, () -> Vector.empty())
.to(Streamable::fromStream).toList().get(0)
.size(),is(3));
}
@Test
代码示例来源:origin: aol/cyclops
@Test
public void xPer(){
SimpleTimer timer = new SimpleTimer();
assertThat(of(1,2,3,4,5,6).xPer(6,100000000,TimeUnit.NANOSECONDS).to(Streamable::fromStream).collect(Collectors.toList()).size(),is(6));
assertThat(timer.getElapsedNanoseconds(),lessThan(60000000l));
}
@Test
内容来源于网络,如有侵权,请联系作者删除!