Sign up ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

The previous iteration at Parallel for loop in Java 8 - follow-up.

The changes are as follows:

  1. MyTask is removed.
  2. Synchronization removed. Now the user is assumed not to tamper with the input list concurrently while some forp is working on it.
  3. Actual forp implemented using Java 8 -facilities.

The only changed file (ParallelFor.java):

package net.coderodde.util;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * This class implements the parallel for loop. It is assumed that two distinct
 * tasks in the loop are independent, i.e., one task needs no output data from
 * another task.
 * 
 * @author Rodion Efremov
 * @version I
 */
public class ParallelFor {

    /**
     * Implements the actual parallel for loop. The user is responsible for not
     * to modify <code>inputList</code> while some invocation of 
     * <code>forp</code> is using it.
     * 
     * @param <I>        the type of input data.
     * @param <O>        the type of output data.
     * @param inputList  the list of individual arguments to the routine to 
     *                   parallelize. 
     * @param body       the actual function transforming an input datum into an
     *                   output datum. May be specified in the form of a 
     *                   lambda expression.
     * @return the list of output data in the same order as input data.
     */
    public static final <I, O> 
        List<O> forp(final List<I> inputList,
                     final Function<I, O> body) {
            return inputList.parallelStream()
                            .map(body)
                            .collect(Collectors.toList());
    }
}
share|improve this question
    
Could you include the other code also in this question? That makes it easier to review in my opinion. – skiwi Dec 19 '14 at 10:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.