public Application(final List<RegisterEntry> entries) { this.entries = Seq.fromIterable(entries); }
public ServerData(int port, PersistentList resources, ApplicationContext rootContext, String baseUrlPattern, Module module) { this.port = port; this.module = module; this.resources = resources==null ? Seq.of() :resources; this.rootContext = rootContext; this.baseUrlPattern = baseUrlPattern; } public ServerData(int port, List resources,
default Seq<T> appendAll(Iterable<? extends T> it){ Seq<T> value = narrow(fromIterable(it)); return value.prependAll(this); } default Seq<T> prepend(T value){
@Test public void fromNull(){ System.out.println(Option.fromIterable(Seq.of().plus(null))); assertThat(Option.some(null), not(equalTo(Option.none()))); assertThat(Option.none(), not(equalTo(Option.some(null)))); assertThat(Option.fromIterable(Seq.of()),equalTo(Option.none())); assertThat(Option.fromIterable(Seq.of().plus(null)),equalTo(Option.some(null))); // System.out.println(Option.fromPublisher(Seq.of(null,190))); // assertThat(Option.fromPublisher(Seq.of(null,190)),equalTo(Option.some(null))); assertThat(Option.fromFuture(Future.ofResult(null)),equalTo(Option.some(null))); } @Test
static <T,R> Seq<R> tailRec(T initial, Function<? super T, ? extends Seq<? extends Either<T, R>>> fn) { Seq<Either<T, R>> next = Seq.of(Either.left(initial)); boolean newValue[] = {true}; for(;;){ next = next.flatMap(e -> e.fold(s -> { newValue[0]=true; return fn.apply(s); }, p -> { newValue[0]=false; return Seq.of(e); })); if(!newValue[0]) break; } return Seq.fromStream(Either.sequenceRight(next).orElse(ReactiveSeq.empty())); } static <T> Seq<T> fill(T t, int max){
@Override default boolean containsValue(T value) { return stream().filter(i->Objects.equals(i,value)).findFirst().isPresent(); }
private boolean cleanupSubsAndReqs(Seq<ActiveSubscriber> localActiveSubs, SubscriberRequests state) { ActiveSubscriber active =null; for (int i = 0; i < localActiveSubs.size() && (active=localActiveSubs.getOrElse(i,null)).queue.isEmpty() && sub.isOpen; i++) { if (!sub.isOpen) { return true; } state.setNextActive(active); state.cleanup(); } return false; }
public static final <A> Seq<Iterable<A>> toBufferingCopier(final Iterable<A> it, final int copies,Supplier<Deque<A>> bufferSupplier) { return Seq.range(0,copies) .zipWithIndex() .map(t->() -> toBufferingCopier(it.iterator(),copies,bufferSupplier).getOrElseGet(t._2().intValue(), ()->Arrays.<A>asList().iterator())); }
@Test public void bufferingCopierTest(){ for(int i=0;i<10;i++) { for(int k=1;k<5;k++) { System.out.println (" Length : " + i + " - copies " + k); Seq<Iterable<Integer>> list = Streams.toBufferingCopier(LazySeq.range(0, i), k); Seq<Integer> result = list.map(it -> LazySeq.fromIterable(it)) .flatMap(s -> s); for (int x = 0; x < i; x++) { assertThat("Failed on " + i + " and " + k,result, hasItem(x)); } assertThat("Failed on " + i + " and " + k,result.size(), equalTo(i * k)); } } } @Test
default <R> ReactiveSeq<R> fanOut(Function<? super ReactiveSeq<T>, ? extends ReactiveSeq<? extends R>> path1, Function<? super ReactiveSeq<T>, ? extends ReactiveSeq<? extends R>> path2, Function<? super ReactiveSeq<T>, ? extends ReactiveSeq<? extends R>> path3, Function<? super ReactiveSeq<T>, ? extends ReactiveSeq<? extends R>> path4){ Seq<ReactiveSeq<T>> list = multicast(4); Publisher<R> pub2 = (Publisher<R>)path2.apply(list.getOrElse(1,empty())); Publisher<R> pub3 = (Publisher<R>)path3.apply(list.getOrElse(2,empty())); Publisher<R> pub4 = (Publisher<R>)path4.apply(list.getOrElse(3,empty())); ReactiveSeq<R> seq = (ReactiveSeq<R>)path1.apply(list.getOrElse(0,empty())); return seq.mergeP(pub2,pub3,pub4); } default <R> ReactiveSeq<R> parallelFanOut(ForkJoinPool fj,Function<? super Stream<T>, ? extends Stream<? extends R>> path1,
default Seq<Tuple2<T,BigDecimal>> withPercentiles(){ Seq<T> list = stream().seq(); int precision = new Double(Math.log10(list.size())).intValue(); return list.zipWithIndex().map(t -> t.map2(idx -> { double d = (idx / new Double(list.size())); return new BigDecimal((d*100),new MathContext(precision)); })); } /*
public static <T,R> Managed<Seq<R>> traverse(Function<? super T,? extends R> fn, Iterable<Managed<T>> stream) { Seq<Managed<R>> s = Seq.fromIterable(stream) .map(j->j.map(fn)); return sequence(s); } public static <T> Managed<T> narrow(Managed<? extends T> broad){