[ https://issues.apache.org/jira/browse/GROOVY-11486?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles updated GROOVY-11486: --------------------------------- Description: The groovy method {{flatten}} for {{Object[]}}, {{Collection}}, {{Iterable}}, {{List}}, {{Set}} and {{SortedSet}} does not inference to the correct return type except for the case where there were no aggregate elements to flatten. There isn't anything the type checker can do to detect the return type for non-trivial cases, but the {{flatten}} methods that accept a transform are a reasonable model: {code:java} public static <T, E> Collection<T> flatten(Iterable<E> self, Closure<?> flattenUsing) { // ... } {code} This allows the programmer to declare the expected list type: {code:groovy} def list = [1,[2],[[3],[4]]] Collection<Integer> coll = list1.flatten(Closure.IDENTITY) {code} was: The groovy method {{flatten}} for {{Object[]}}, {{Collection}}, {{Iterable}}, {{List}}, {{Set}} and {{SortedSet}} does not inference to the correct return type except for the case where there were no aggregate elements to flatten. There isn't anything the type checker can do to detect the return type for non-trivial cases, but the {{flatten}} methods that accept a transform are a reasonable model: {code:java} public static <T, E> Collection<T> flatten(Iterable<E> self, Closure<?> flattenUsing) { // ... } {code} This allows the programmer to declare the expected list type: {code:groovy} def list1 = [1,[2],[[3],[4]]] List<Integer> list2 = list1.flatten(Closure.IDENTITY) {code} > DGM flatten return type is often incorrect > ------------------------------------------ > > Key: GROOVY-11486 > URL: https://issues.apache.org/jira/browse/GROOVY-11486 > Project: Groovy > Issue Type: Bug > Reporter: Eric Milles > Priority: Major > > The groovy method {{flatten}} for {{Object[]}}, {{Collection}}, {{Iterable}}, > {{List}}, {{Set}} and {{SortedSet}} does not inference to the correct return > type except for the case where there were no aggregate elements to flatten. > There isn't anything the type checker can do to detect the return type for > non-trivial cases, but the {{flatten}} methods that accept a transform are a > reasonable model: > {code:java} > public static <T, E> Collection<T> flatten(Iterable<E> self, Closure<?> > flattenUsing) { > // ... > } > {code} > This allows the programmer to declare the expected list type: > {code:groovy} > def list = [1,[2],[[3],[4]]] > Collection<Integer> coll = list1.flatten(Closure.IDENTITY) > {code} -- This message was sent by Atlassian Jira (v8.20.10#820010)