You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2025/06/04 14:46:00 UTC

[jira] [Closed] (GROOVY-11486) DGM flatten return type is often incorrect

     [ https://issues.apache.org/jira/browse/GROOVY-11486?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King closed GROOVY-11486.
------------------------------

> 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
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 5.0.0-beta-1
>
>
> 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 type:
> {code:groovy}
> def list = [1,[2],[[3],[4]]]
> Collection<Integer> coll = list.flatten(Closure.IDENTITY)
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)