Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best style for iterating through two lists in unison

Here is what I just wrote:

 public void mutate(){
    ListIterator<Double> git = genome.listIterator();
    Iterator<Double> mit = mutationStrategies.iterator();
    while (git.hasNext() && mit.hasNext()){
        git.set(alleleUpdate(git.next(), mit.next()));
    }

}

Is this the most efficient and clearest way of doing that? All that is necessary to know is that the genome list is setting its values according to some function that takes its current value and the current value of mutationStrategies. (If your into evolutionary stuff, this is for an Evolution Strategies algorithm).

like image 640
Ben B. Avatar asked Nov 05 '22 07:11

Ben B.


1 Answers

It's hard to imagine how it could be tighter. "Replace each git (whatever those are) with a mutated version of itself, stopping if we run out of mutation strategies."

like image 76
Tony Ennis Avatar answered Nov 09 '22 04:11

Tony Ennis