io.vavr.collection.Vector.empty()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(192)

本文整理了Java中io.vavr.collection.Vector.empty()方法的一些代码示例,展示了Vector.empty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vector.empty()方法的具体详情如下:
包路径:io.vavr.collection.Vector
类名称:Vector
方法名:empty

Vector.empty介绍

[英]Returns the empty Vector.
[中]返回空向量。

代码示例

代码示例来源:origin: vavr-io/vavr

/**
 * Alias for {@link Vector#empty()}
 *
 * @param <T> Component type of element.
 * @return A singleton instance of empty {@link Vector}
 */
public static <T> IndexedSeq<T> IndexedSeq() {
  return Vector.empty();
}

代码示例来源:origin: vavr-io/vavr

/**
 * Alias for {@link Vector#empty()}
 *
 * @param <T> Component type of element.
 * @return A singleton instance of empty {@link Vector}
 */
public static <T> Vector<T> Vector() {
  return Vector.empty();
}

代码示例来源:origin: vavr-io/vavr

/**
 * Converts this to a {@link Vector}.
 *
 * @return A new {@link Vector}.
 */
default Vector<T> toVector() {
  return ValueModule.toTraversable(this, Vector.empty(), Vector::of, Vector::ofAll);
}

代码示例来源:origin: vavr-io/vavr

/**
 * Returns a Vector containing {@code n} times the given {@code element}
 *
 * @param <T>     Component type of the Vector
 * @param n       The number of elements in the Vector
 * @param element The element
 * @return A Vector of size {@code n}, where each element is the given {@code element}.
 */
public static <T> Vector<T> fill(int n, T element) {
  return io.vavr.collection.Collections.fillObject(n, element, empty(), Vector::of);
}

代码示例来源:origin: vavr-io/vavr

/**
 * Returns a Vector containing {@code n} values supplied by a given Supplier {@code s}.
 *
 * @param <T> Component type of the Vector
 * @param n   The number of elements in the Vector
 * @param s   The Supplier computing element values
 * @return A Vector of size {@code n}, where each element contains the result supplied by {@code s}.
 * @throws NullPointerException if {@code s} is null
 */
public static <T> Vector<T> fill(int n, Supplier<? extends T> s) {
  Objects.requireNonNull(s, "s is null");
  return io.vavr.collection.Collections.fill(n, s, empty(), Vector::of);
}

代码示例来源:origin: vavr-io/vavr

@Override
public Iterator<Vector<T>> crossProduct(int power) { return io.vavr.collection.Collections.crossProduct(empty(), this, power); }

代码示例来源:origin: vavr-io/vavr

/**
 * Returns a Vector containing {@code n} values of a given Function {@code f}
 * over a range of integer values from 0 to {@code n - 1}.
 *
 * @param <T> Component type of the Vector
 * @param n   The number of elements in the Vector
 * @param f   The Function computing element values
 * @return A Vector consisting of elements {@code f(0),f(1), ..., f(n - 1)}
 * @throws NullPointerException if {@code f} is null
 */
public static <T> Vector<T> tabulate(int n, Function<? super Integer, ? extends T> f) {
  Objects.requireNonNull(f, "f is null");
  return io.vavr.collection.Collections.tabulate(n, f, empty(), Vector::of);
}

代码示例来源:origin: vavr-io/vavr

@Override
public <U, R> IndexedSeq<R> zipWith(Iterable<? extends U> that, BiFunction<? super Character, ? super U, ? extends R> mapper) {
  Objects.requireNonNull(that, "that is null");
  Objects.requireNonNull(mapper, "mapper is null");
  IndexedSeq<R> result = Vector.empty();
  final io.vavr.collection.Iterator<Character> list1 = iterator();
  final java.util.Iterator<? extends U> list2 = that.iterator();
  while (list1.hasNext() && list2.hasNext()) {
    result = result.append(mapper.apply(list1.next(), list2.next()));
  }
  return result;
}

代码示例来源:origin: vavr-io/vavr

@Override
public <U> IndexedSeq<U> flatMap(Function<? super Character, ? extends Iterable<? extends U>> mapper) {
  Objects.requireNonNull(mapper, "mapper is null");
  if (isEmpty()) {
    return Vector.empty();
  } else {
    IndexedSeq<U> result = Vector.empty();
    for (int i = 0; i < length(); i++) {
      for (U u : mapper.apply(get(i))) {
        result = result.append(u);
      }
    }
    return result;
  }
}

代码示例来源:origin: vavr-io/vavr

private static <T> Vector<T> ofAll(BitMappedTrie<T> trie) {
  return (trie.length() == 0)
      ? empty()
      : new Vector<>(trie);
}

代码示例来源:origin: vavr-io/vavr

@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);
}

代码示例来源:origin: vavr-io/vavr

@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);
}

代码示例来源:origin: vavr-io/vavr

@Override
public <T1, T2, T3> Tuple3<IndexedSeq<T1>, IndexedSeq<T2>, IndexedSeq<T3>> unzip3(Function<? super Character, Tuple3<? extends T1, ? extends T2, ? extends T3>> unzipper) {
  Objects.requireNonNull(unzipper, "unzipper is null");
  IndexedSeq<T1> xs = Vector.empty();
  IndexedSeq<T2> ys = Vector.empty();
  IndexedSeq<T3> zs = Vector.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);
}

代码示例来源:origin: vavr-io/vavr

@Override
public <T1, T2> Tuple2<IndexedSeq<T1>, IndexedSeq<T2>> unzip(Function<? super Character, Tuple2<? extends T1, ? extends T2>> unzipper) {
  Objects.requireNonNull(unzipper, "unzipper is null");
  IndexedSeq<T1> xs = Vector.empty();
  IndexedSeq<T2> ys = Vector.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);
}

代码示例来源:origin: vavr-io/vavr

@Override
public <U> IndexedSeq<U> zipWithIndex(BiFunction<? super Character, ? super Integer, ? extends U> mapper) {
  Objects.requireNonNull(mapper, "mapper is null");
  IndexedSeq<U> result = Vector.empty();
  for (int i = 0; i < length(); i++) {
    result = result.append(mapper.apply(get(i), i));
  }
  return result;
}

代码示例来源:origin: vavr-io/vavr

@Override
public <U> IndexedSeq<U> map(Function<? super Character, ? extends U> mapper) {
  Objects.requireNonNull(mapper, "mapper is null");
  IndexedSeq<U> result = Vector.empty();
  for (int i = 0; i < length(); i++) {
    result = result.append(mapper.apply(get(i)));
  }
  return result;
}

代码示例来源:origin: vavr-io/vavr

@Override
public <U> IndexedSeq<Tuple2<Character, U>> zipAll(Iterable<? extends U> that, Character thisElem, U thatElem) {
  Objects.requireNonNull(that, "that is null");
  IndexedSeq<Tuple2<Character, U>> result = Vector.empty();
  final io.vavr.collection.Iterator<Character> list1 = iterator();
  final java.util.Iterator<? extends U> list2 = that.iterator();
  while (list1.hasNext() || list2.hasNext()) {
    final Character elem1 = list1.hasNext() ? list1.next() : thisElem;
    final U elem2 = list2.hasNext() ? list2.next() : thatElem;
    result = result.append(Tuple.of(elem1, elem2));
  }
  return result;
}

代码示例来源:origin: vavr-io/vavr

@Override
public Tuple2<Vector<T>, Vector<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)) {
      return (i == (length() - 1)) ? Tuple.of(this, empty())
                     : Tuple.of(take(i + 1), drop(i + 1));
    }
  }
  return Tuple.of(this, empty());
}

代码示例来源:origin: vavr-io/vavr

@Override
public Vector<T> slice(int beginIndex, int endIndex) {
  if ((beginIndex >= endIndex) || (beginIndex >= size()) || isEmpty()) {
    return empty();
  } else if ((beginIndex <= 0) && (endIndex >= length())) {
    return this;
  } else {
    return take(endIndex).drop(beginIndex);
  }
}

代码示例来源:origin: vavr-io/vavr

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)));
  }
}

相关文章