Paul King created GROOVY-11678: ---------------------------------- Summary: Create DGM#subList(IntRange) method Key: GROOVY-11678 URL: https://issues.apache.org/jira/browse/GROOVY-11678 Project: Groovy Issue Type: New Feature Reporter: Paul King Assignee: Paul King
We recently added some DGM variants on Lists which take an IntRange. Rather than keep adding such variants, it makes more sense to provide a subList method that takes a range. {code:groovy} def list = [1, 2, 3, 3, 4, 4, 5, 6, 7] assert list.partitionPoint(0..<4) { it <= 20 } == 4 // alt1 assert list.subList(0..<4).partitionPoint { it <= 20 } == 4 // alt2 {code} It would allow us to offer the second alternative instead of the first, potentially removing the need for one variant. Another example: {code:groovy} def nums = [5, 9, 1, 7, 3, 4, 8, 6, 0, 2] nums.sort(0..4) // alt1 nums.subList(0..4).sort() // alt2 assert nums == [1, 3, 5, 7, 9, 4, 8, 6, 0, 2] {code} The other mutating methods, e.g. {{shuffle}}, {{unique}}, {{clear}}, could also be used and we don't need more variants. It would still make sense to keep some variants, e.g.: {code:groovy} assert nums.toSorted(0..4) == [1, 3, 5, 7, 9, 4, 8, 6, 0, 2] {code} Since we sort on the int range but return the whole list. It may also make sense to keep variants where we want to offer the same functionality with index selection across more aggregates, e.g. lists and arrays. -- This message was sent by Atlassian Jira (v8.20.10#820010)