Copilot commented on code in PR #2214:
URL: https://github.com/apache/groovy/pull/2214#discussion_r2075538165


##########
src/main/java/org/codehaus/groovy/runtime/ArrayGroovyMethods.java:
##########
@@ -7260,6 +7260,405 @@ public static <T> T[] plus(T[] left, Object right) {
         return result;
     }
 
+    
//--------------------------------------------------------------------------
+    // putAt
+
+    /**
+     * A helper method to allow arrays to be set with subscript operators.
+     * <pre class="groovyTestCase">
+     * Integer[] from = [70, 80, 90]
+     * Integer[] nums = [1, 2, 3, 4, 5]
+     * nums[1..3] = from
+     * assert nums == [1, 70, 80, 90, 5]
+     * </pre>
+     *
+     * @param self   an array
+     * @param range  the subset of the array to set
+     * @param source the source array from which new values will come
+     * @throws IndexOutOfBoundsException if the source doesn't have sufficient 
elements or the IntRange is too big for the self array
+     * @since 5.0.0
+     */
+    public static <T> void putAt(T[] self, IntRange range, T[] source) {
+        RangeInfo info = range.subListBorders(self.length);
+        System.arraycopy(source, 0, self, info.from, info.to - info.from);
+    }
+
+    /**
+     * A helper method to allow arrays to be set with subscript operators.
+     * Null will be used if the source iterable has insufficient elements.
+     * <pre class="groovyTestCase">
+     * def from = [70, 80, 90]
+     * Integer[] nums = [1, 2, 3, 4, 5]
+     * nums[1..3] = from
+     * assert nums == [1, 70, 80, 90, 5]
+     * </pre>
+     *
+     * @param self   an array
+     * @param range  the subset of the array to set
+     * @param source the source array from which new values will come
+     * @since 5.0.0
+     */
+    public static <T> void putAt(T[] self, IntRange range, Iterable<T> source) 
{
+        RangeInfo info = range.subListBorders(self.length);

Review Comment:
   The logic for processing Iterable sources is duplicated across various putAt 
methods. Consider refactoring the common iteration code into a private helper 
method to improve maintainability.
   ```suggestion
           RangeInfo info = range.subListBorders(self.length);
           assignFromIterable(self, info, source);
       }
   
       private static <T> void assignFromIterable(T[] self, RangeInfo info, 
Iterable<T> source) {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@groovy.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to