Example #1
0
 @Override
 public Tuple2<Array<T>, Array<T>> splitAtInclusive(Predicate<? super T> predicate) {
   Objects.requireNonNull(predicate, "predicate is null");
   for (int i = 0; i < length(); i++) {
     final T value = get(i);
     if (predicate.test(value)) {
       if (i == length() - 1) {
         return Tuple.of(this, empty());
       } else {
         return Tuple.of(take(i + 1), drop(i + 1));
       }
     }
   }
   return Tuple.of(this, empty());
 }
Example #2
0
 @Override
 public <T1, T2> Tuple2<Array<T1>, Array<T2>> unzip(
     Function<? super T, Tuple2<? extends T1, ? extends T2>> unzipper) {
   Objects.requireNonNull(unzipper, "unzipper is null");
   if (isEmpty()) {
     return Tuple.of(empty(), empty());
   } else {
     final Object[] xs = new Object[length()];
     final Object[] ys = new Object[length()];
     for (int i = 0; i < length(); i++) {
       final Tuple2<? extends T1, ? extends T2> t = unzipper.apply(get(i));
       xs[i] = t._1;
       ys[i] = t._2;
     }
     return Tuple.of(wrap(xs), wrap(ys));
   }
 }
Example #3
0
 @Override
 public Tuple2<Array<T>, Array<T>> partition(Predicate<? super T> predicate) {
   Objects.requireNonNull(predicate, "predicate is null");
   final java.util.List<T> left = new ArrayList<>(), right = new ArrayList<>();
   for (T t : this) {
     (predicate.test(t) ? left : right).add(t);
   }
   return Tuple.of(ofAll(left), ofAll(right));
 }
Example #4
0
 @Override
 public Tuple2<Array<T>, Array<T>> span(Predicate<? super T> predicate) {
   Objects.requireNonNull(predicate, "predicate is null");
   return Tuple.of(takeWhile(predicate), dropWhile(predicate));
 }
Example #5
0
 @Override
 public Tuple2<Array<T>, Array<T>> splitAt(Predicate<? super T> predicate) {
   Objects.requireNonNull(predicate, "predicate is null");
   final Array<T> init = takeWhile(predicate.negate());
   return Tuple.of(init, drop(init.length()));
 }
Example #6
0
 @Override
 public Tuple2<Array<T>, Array<T>> splitAt(long n) {
   return Tuple.of(take(n), drop(n));
 }