@Override public IndexedSeq<CharSeq> combinations() { return Vector.rangeClosed(0, length()).map(this::combinations).flatMap(Function.identity()); }
/** * Reduces many {@code Lazy} values into a single {@code Lazy} by transforming an * {@code Iterable<Lazy<? extends T>>} into a {@code Lazy<Seq<T>>}. * * @param <T> Type of the lazy values. * @param values An iterable of lazy values. * @return A lazy sequence of values. * @throws NullPointerException if values is null */ @SuppressWarnings("Convert2MethodRef") // TODO should be fixed in JDK 9 and Idea public static <T> Lazy<Seq<T>> sequence(Iterable<? extends Lazy<? extends T>> values) { Objects.requireNonNull(values, "values is null"); return Lazy.of(() -> Vector.ofAll(values).map(lazy -> lazy.get())); }
@Override public Vector<Vector<T>> combinations() { return rangeClosed(0, length()).map(this::combinations).flatMap(Function.identity()); }
/** * Chooses one of the given generators according to their frequency. * Only generators with positive frequencies ares used in returned * generator. * * @param generators A non-empty traversable of Tuples (frequency, generator) * @param <T> Type to be generated * @return A new T generator * @throws java.lang.NullPointerException if generators is null * @throws java.lang.IllegalArgumentException if generators doesn't contain any generator with positive frequency */ static <T> Gen<T> frequency(Iterable<Tuple2<Integer, Gen<T>>> generators) { Objects.requireNonNull(generators, "generators is null"); final Vector<Tuple2<Integer, Gen<T>>> filtered = Iterator.ofAll(generators) .filter(t -> t._1() > 0).toVector(); if (filtered.isEmpty()) { throw new IllegalArgumentException("no generator with positive weight"); } final int size = filtered.map(t -> t._1).sum().intValue(); return choose(1, size).flatMap(n -> GenModule.frequency(n, filtered.iterator())); }
static <T> Vector<Vector<T>> apply(Vector<T> elements, int k) { return (k == 0) ? Vector.of(Vector.empty()) : elements.zipWithIndex().flatMap( t -> apply(elements.drop(t._2 + 1), (k - 1)).map((Vector<T> c) -> c.prepend(t._1))); } }
/** * Map implementation for the DataRowCollection class. * * @param <U> Mapped return type. * @param mapper The map function. * @return Returns a sequence of the applied map. */ public <U> Seq<U> map(Function<? super DataRow, ? extends U> mapper) { return this.rows.map(mapper); }
/** * Map implementation for the DataColumnCollection class. * * @param <U> Mapped return type. * @param mapper The map function. * @return Returns a sequence of the applied map. */ public <U> Seq<U> map(Function<? super IDataColumn, ? extends U> mapper) { return this.columns.map(mapper); }
/** * Wraps the given event in a Tagged object, instructing the journal to add a tag to it. */ private Iterable<Tagged> tagged(Iterable<E> event) { return Vector.ofAll(event).map(this::tagged); }
@Override public IndexedSeq<CharSeq> combinations() { return Vector.rangeClosed(0, length()).map(this::combinations).flatMap(Function.identity()); }
/** * Reduces many {@code Lazy} values into a single {@code Lazy} by transforming an * {@code Iterable<Lazy<? extends T>>} into a {@code Lazy<Seq<T>>}. * * @param <T> Type of the lazy values. * @param values An iterable of lazy values. * @return A lazy sequence of values. * @throws NullPointerException if values is null */ @SuppressWarnings("Convert2MethodRef") // TODO should be fixed in JDK 9 and Idea public static <T> Lazy<Seq<T>> sequence(Iterable<? extends Lazy<? extends T>> values) { Objects.requireNonNull(values, "values is null"); return Lazy.of(() -> Vector.ofAll(values).map(lazy -> lazy.get())); }
@Override public Vector<Vector<T>> combinations() { return rangeClosed(0, length()).map(this::combinations).flatMap(Function.identity()); }
static <T> Vector<Vector<T>> apply(Vector<T> elements, int k) { return (k == 0) ? Vector.of(Vector.empty()) : elements.zipWithIndex().flatMap( t -> apply(elements.drop(t._2 + 1), (k - 1)).map((Vector<T> c) -> c.prepend(t._1))); } }