/** * Cross join 2 streams into one. * <p> * <code><pre> * // (tuple(1, "a"), tuple(1, "b"), tuple(2, "a"), tuple(2, "b")) * Seq.of(1, 2).crossJoin(Seq.of("a", "b")) * </pre></code> */ /// @Generated("This method was generated using jOOQ-tools") static <T1, T2> Seq<Tuple2<T1, T2>> crossJoin(Seq<? extends T1> s1, Seq<? extends T2> s2) { List<? extends T2> list = s2.toList(); return seq(s1).flatMap(v1 -> seq(list).map(v2 -> tuple(v1, v2))) .onClose(SeqUtils.closeAll(s1, s2)); }
/** * Zip 8 streams into one. * <p> * <code><pre> * // (tuple(1, "a"), tuple(2, "b"), tuple(3, "c")) * Seq.of(1, 2, 3).zip(Seq.of("a", "b", "c")) * </pre></code> */ /// @Generated("This method was generated using jOOQ-tools") static <T1, T2, T3, T4, T5, T6, T7, T8> Seq<Tuple8<T1, T2, T3, T4, T5, T6, T7, T8>> zip(Stream<? extends T1> s1, Stream<? extends T2> s2, Stream<? extends T3> s3, Stream<? extends T4> s4, Stream<? extends T5> s5, Stream<? extends T6> s6, Stream<? extends T7> s7, Stream<? extends T8> s8) { return zip(seq(s1), seq(s2), seq(s3), seq(s4), seq(s5), seq(s6), seq(s7), seq(s8)); }
public static List<HtmlCssTheme> popularThemes() { HttpUrl url = HttpUrl.parse(POPULAR_THEMES_URL); Request request = new Request.Builder().url(url).get().build(); String html = Retry.retryUntilSuccessfulWithBackoff( () -> client.newCall(request).execute() ); Elements elements = Jsoup.parse(html).select("#products .thumbnail"); List<HtmlCssTheme> themes = Seq.seq(elements).map(TemplateMonsterScraper::themeFromElement).toList(); return themes; }
/** * Wrap multiple collectors in a single Collector instance, so they can all run against a single Stream * e.g * {@code * PTuple2<Set<Integer>,List<Integer>> res = Stream.of(1, 2, 2) .collect(tuple(Collectors.toSet(),Collectors.toList()).asCollector()); * * } * * Filters all non-Collector instances out of the Tuple * * @return Collector */ default <T,A,R> Collector<T,A,R> asCollector(){ List<Collector> collectors = (List)getCachedValues().stream().filter(c-> c instanceof Collector).collect(Collectors.toList()); final Supplier supplier = ()-> collectors.stream().map(c->c.supplier().get()).collect(Collectors.toList()); final BiConsumer accumulator = (acc,next) -> { Seq.seq(collectors.stream().iterator()).<Object,PTuple2<Collector,Object>>zip(Seq.seq((List)acc),(a,b)->PowerTuples.<Collector,Object>tuple(a,b)) .forEach( t -> t.v1().accumulator().accept(t.v2(),next)); }; final BinaryOperator combiner = (t1,t2)-> new TupleImpl(collectors.stream().map(c->c.combiner().apply(t1,t2)).collect(Collectors.toList()),arity()); return (Collector) Collector.of( supplier, accumulator , combiner, values-> new TupleImpl(Seq.seq(collectors.stream().iterator()).<Object,PTuple2<Collector,Object>>zip(Seq.seq((List)values),(a,b)->PowerTuples.<Collector,Object>tuple(a,b)).map(t->t.v1().finisher().apply(t.v2())).toList(),arity())); }
private static List<Field> getFieldData( Class class1) { return fields.computeIfAbsent(class1, cl ->{ return Seq.iterate(class1, c->c.getSuperclass()) .limitWhile(c->c!=Object.class) .reverse() .flatMap(c->Stream.of(c.getDeclaredFields())) .filter(f->!Modifier.isStatic(f.getModifiers())) .map(f -> { f.setAccessible(true); return f;}) .collect(Collectors.toList()); }); }
/** * Outer apply 2 functions to a stream. * <p> * <code><pre> * // (tuple(0, null), tuple(1, 0), tuple(2, 0), tuple(2, 1)) * Seq.of(0, 1, 2).outerApply(t -> Seq.range(0, t)) * </pre></code> */ /// @Generated("This method was generated using jOOQ-tools") static <T1, T2> Seq<Tuple2<T1, T2>> outerApply(Seq<? extends T1> seq, Function<? super T1, ? extends Seq<? extends T2>> function2) { return seq.flatMap(t1 -> function2.apply(t1).onEmpty(null).map(t2 -> tuple(t1, t2))) .onClose(seq::close); }
public <U> U reduceResults(final Collection<FastFuture<T>> results, final Function<FastFuture, T> safeJoin, final U identity, final BiFunction<U, ? super T, U> accumulator) { final Stream<FastFuture<T>> streamToUse = results.stream(); final U result = Seq.seq(streamToUse) .map(safeJoin) .filter(v -> v != MissingValue.MISSING_VALUE) .foldLeft(identity, accumulator); consumer.getResults() .clear(); return result; } }
/** * Keep only those elements in a stream that are of a given type. * <p> * <code><pre> * // (1, 2, 3) * Seq.of(1, "a", 2, "b", 3).ofType(Integer.class) * </pre></code> */ @SuppressWarnings("unchecked") static <T, U> Seq<U> ofType(Stream<? extends T> stream, Class<? extends U> type) { return seq(stream).filter(type::isInstance).map(t -> (U) t); }
/** * Cross apply 2 functions to a stream. * <p> * <code><pre> * // (tuple(1, 0), tuple(2, 0), tuple(2, 1)) * Seq.of(1, 2).crossApply(t -> Seq.range(0, t)) * </pre></code> */ /// @Generated("This method was generated using jOOQ-tools") static <T1, T2> Seq<Tuple2<T1, T2>> crossApply(Seq<? extends T1> seq, Function<? super T1, ? extends Seq<? extends T2>> function2) { return seq.flatMap(t1 -> function2.apply(t1).map(t2 -> tuple(t1, t2))) .onClose(seq::close); }
/** * The range between two values. * * @param fromInclusive The lower bound * @param toInclusive The upper bound * @param step The increase between two values */ static Seq<Short> rangeClosed(short fromInclusive, short toInclusive, int step) { return toInclusive < fromInclusive ? empty() : iterate(fromInclusive, t -> Short.valueOf((short) (t + step))).limitWhile(t -> t <= toInclusive); }