> On 15 Oct 2015, at 16:28, Stephen Colebourne <scolebou...@joda.org> wrote: > > I've been working on a Java 8 wrapper class around double[] in my day > job, and added the following factory method: > > /** > * Obtains an instance with entries filled using a function. > * <p> > * The function is passed the array index and returns the value for > that index. > * > * @param size the number of elements > * @param valueFunction the function used to populate the value > * @return an array initialized using the function > */ > public static DoubleMatrix1D of(int size, IntToDoubleFunction valueFunction) > { > if (size == 0) { > return EMPTY; > } > double[] array = new double[size]; > for (int i = 0; i < array.length; i++) { > array[i] = valueFunction.applyAsDouble(i); > } > return new DoubleMatrix1D(array); > } >
Within that method you can use Arrays.setAll(array, valueFunction). In hindsight it would have been useful for that method to return the filled array. Paul.