@Override public <T1, T2, T3> Tuple3<Vector<T1>, Vector<T2>, Vector<T3>> unzip3(Function<? super T, Tuple3<? extends T1, ? extends T2, ? extends T3>> unzipper) { Objects.requireNonNull(unzipper, "unzipper is null"); Vector<T1> xs = empty(); Vector<T2> ys = empty(); Vector<T3> zs = empty(); for (int i = 0; i < length(); i++) { final Tuple3<? extends T1, ? extends T2, ? extends T3> t = unzipper.apply(get(i)); xs = xs.append(t._1); ys = ys.append(t._2); zs = zs.append(t._3); } return Tuple.of(xs, ys, zs); }
@Override public Vector<Vector<T>> permutations() { if (isEmpty()) { return empty(); } else if (length() == 1) { return of(this); } else { Vector<Vector<T>> results = empty(); for (T t : distinct()) { for (Vector<T> ts : remove(t).permutations()) { results = results.append(of(t).appendAll(ts)); } } return results; } }
@Override public <T1, T2> Tuple2<Vector<T1>, Vector<T2>> unzip(Function<? super T, Tuple2<? extends T1, ? extends T2>> unzipper) { Objects.requireNonNull(unzipper, "unzipper is null"); Vector<T1> xs = empty(); Vector<T2> ys = empty(); for (int i = 0; i < length(); i++) { final Tuple2<? extends T1, ? extends T2> t = unzipper.apply(get(i)); xs = xs.append(t._1); ys = ys.append(t._2); } return Tuple.of(xs, ys); }
@Override public Vector<Vector<T>> permutations() { if (isEmpty()) { return empty(); } else if (length() == 1) { return of(this); } else { Vector<Vector<T>> results = empty(); for (T t : distinct()) { for (Vector<T> ts : remove(t).permutations()) { results = results.append(of(t).appendAll(ts)); } } return results; } }
/** * Reduces many {@code Option}s into a single {@code Option} by transforming an * {@code Iterable<Option<? extends T>>} into a {@code Option<Seq<T>>}. If any of * the Options are {@link Option.None}, then this returns {@link Option.None}. * * @param values An {@code Iterable} of {@code Option}s * @param <T> type of the Options * @return An {@code Option} of a {@link Seq} of results * @throws NullPointerException if {@code values} is null */ static <T> Option<Seq<T>> sequence(Iterable<? extends Option<? extends T>> values) { Objects.requireNonNull(values, "values is null"); Vector<T> vector = Vector.empty(); for (Option<? extends T> value : values) { if (value.isEmpty()) { return Option.none(); } vector = vector.append(value.get()); } return Option.some(vector); }
/** * Reduces many {@code Try}s into a single {@code Try} by transforming an * {@code Iterable<Try<? extends T>>} into a {@code Try<Seq<T>>}. If any of * the {@code Try}s are {@link Try.Failure}, then this returns a {@link Try.Failure}. * * @param values An {@link Iterable} of {@code Try}s * @param <T> type of the Trys * @return A {@code Try} of a {@link Seq} of results * @throws NullPointerException if {@code values} is null */ static <T> Try<Seq<T>> sequence(Iterable<? extends Try<? extends T>> values) { Objects.requireNonNull(values, "values is null"); Vector<T> vector = Vector.empty(); for (Try<? extends T> value : values) { if (value.isFailure()) { return Try.failure(value.getCause()); } vector = vector.append(value.get()); } return Try.success(vector); }
for (Either<? extends L, ? extends R> either : eithers) { if (either.isRight()) { rightValues = rightValues.append(either.get()); } else { return Either.left(either.getLeft());
/** * Adds - Appends a new item to the end of the vector. * * @param vector The vector to add the item to. * @param item The item to add. * @param <T> The vector type. * @return Returns the new vector with the item added. */ public static <T> Try<Vector<T>> addItem(Vector<T> vector, T item) { return Try.success(vector.append(item)); }
@Override public <T1, T2, T3> Tuple3<Vector<T1>, Vector<T2>, Vector<T3>> unzip3(Function<? super T, Tuple3<? extends T1, ? extends T2, ? extends T3>> unzipper) { Objects.requireNonNull(unzipper, "unzipper is null"); Vector<T1> xs = empty(); Vector<T2> ys = empty(); Vector<T3> zs = empty(); for (int i = 0; i < length(); i++) { final Tuple3<? extends T1, ? extends T2, ? extends T3> t = unzipper.apply(get(i)); xs = xs.append(t._1); ys = ys.append(t._2); zs = zs.append(t._3); } return Tuple.of(xs, ys, zs); }
@Override public <T1, T2> Tuple2<Vector<T1>, Vector<T2>> unzip(Function<? super T, Tuple2<? extends T1, ? extends T2>> unzipper) { Objects.requireNonNull(unzipper, "unzipper is null"); Vector<T1> xs = empty(); Vector<T2> ys = empty(); for (int i = 0; i < length(); i++) { final Tuple2<? extends T1, ? extends T2> t = unzipper.apply(get(i)); xs = xs.append(t._1); ys = ys.append(t._2); } return Tuple.of(xs, ys); }
/** * Adds / Appends and item to the end of the column. * * @param value The value to append. * @return Returns a new DataColumn with the new item appended. */ public Try<DataColumn<T>> addItem(T value) { return Try.success(createColumn(this.data.append(value))); }
/** * Reduces many {@code Option}s into a single {@code Option} by transforming an * {@code Iterable<Option<? extends T>>} into a {@code Option<Seq<T>>}. If any of * the Options are {@link Option.None}, then this returns {@link Option.None}. * * @param values An {@code Iterable} of {@code Option}s * @param <T> type of the Options * @return An {@code Option} of a {@link Seq} of results * @throws NullPointerException if {@code values} is null */ static <T> Option<Seq<T>> sequence(Iterable<? extends Option<? extends T>> values) { Objects.requireNonNull(values, "values is null"); Vector<T> vector = Vector.empty(); for (Option<? extends T> value : values) { if (value.isEmpty()) { return Option.none(); } vector = vector.append(value.get()); } return Option.some(vector); }
/** * Reduces many {@code Try}s into a single {@code Try} by transforming an * {@code Iterable<Try<? extends T>>} into a {@code Try<Seq<T>>}. If any of * the {@code Try}s are {@link Try.Failure}, then this returns a {@link Try.Failure}. * * @param values An {@link Iterable} of {@code Try}s * @param <T> type of the Trys * @return A {@code Try} of a {@link Seq} of results * @throws NullPointerException if {@code values} is null */ static <T> Try<Seq<T>> sequence(Iterable<? extends Try<? extends T>> values) { Objects.requireNonNull(values, "values is null"); Vector<T> vector = Vector.empty(); for (Try<? extends T> value : values) { if (value.isFailure()) { return Try.failure(value.getCause()); } vector = vector.append(value.get()); } return Try.success(vector); }
for (Either<? extends L, ? extends R> either : eithers) { if (either.isRight()) { rightValues = rightValues.append(either.get()); } else { return Either.left(either.getLeft());
/** * Attempts to add / append a new item to the end of the column. * A type check is performed before addition. * * @param value The item required to be added. * @return Returns a Success with the new modified DataColumn, or a Failure. */ @Override public Try<IDataColumn> add(Object value) { return Match(GenericExtensions.tryCast(this.type, value)).of( Case($Success($()), typedVal -> Try.of(() -> createColumn(this.data.append(typedVal)))), Case($Failure($()), DataTableException.tryError("tryAdd failed. Item of invalid type passed.")) ); }