partition list - Groovy built-in to split an array into equal sized subarrays? - Stack Overflow

list - Groovy built-in to split an array into equal sized subarrays? - Stack Overflow

def partition ( array , size ) {
   
def partitions = []
   
int partitionCount = array . size () / size

    partitionCount
. times { partitionNumber ->
       
def start = partitionNumber * size
       
def end = start + size - 1
        partitions
<< array [ start .. end ]    
   
}

   
if ( array . size () % size ) partitions << array [ partitionCount * size ..- 1 ]
   
return partitions    
}

你可能感兴趣的:(partition)