Ejemplo n.º 1
0
 /**
  * Returns a Tree 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 Tree
  * @param n The number of elements in the Tree
  * @param f The Function computing element values
  * @return A Tree consisting of elements {@code f(0),f(1), ..., f(n - 1)}
  * @throws NullPointerException if {@code f} is null
  */
 static <T> Tree<T> tabulate(int n, Function<? super Integer, ? extends T> f) {
   Objects.requireNonNull(f, "f is null");
   return Collections.tabulate(n, f, Tree.empty(), Tree::of);
 }
Ejemplo n.º 2
0
 /**
  * Returns an Array 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 Array
  * @param n The number of elements in the Array
  * @param f The Function computing element values
  * @return An Array consisting of elements {@code f(0),f(1), ..., f(n - 1)}
  * @throws NullPointerException if {@code f} is null
  */
 public static <T> Array<T> tabulate(int n, Function<? super Integer, ? extends T> f) {
   Objects.requireNonNull(f, "f is null");
   return Collections.tabulate(n, f, empty(), Array::of);
 }