Issue Details (XML | Word | Printable)

Key: GROOVY-2903
Type: Test Test
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Paul King
Reporter: Robert Fischer (Smokejumper Consulting)
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
groovy

[ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ]

Created: 14/Jun/08 11:34 PM   Updated: 17/Jun/08 05:41 PM
Component/s: groovy-jdk
Affects Version/s: 1.6-beta-1
Fix Version/s: 1.5.7

Time Tracking:
Not Specified

File Attachments: 1. Text File DefaultGroovyMethods.java.docupdate.patch (0.4 kB)
2. Text File DefaultGroovyMethodsTest.java.docupdate.patch (6 kB)

Environment: Originally Run on OS-X
Issue Links:
Related
 

Testcase included: yes
Patch Submitted: Yes


 Description  « Hide
The JavaDoc of flatten says: "This collection and any nested collections have their contents (recursively) added to the new collection." However, if it encounters a map, it exacts the value list and flattens that. This is odd on two points – 1) a Map is not a Collection, so it shouldn't be touched by #flatten according to that definition, and 2) there is no map#flatten which corresponds to this behavior.

This makes it sound like a bug to me, but there may be existing code dependent on the issue. So the attached patches just document and demonstrate the issue.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Paul King added a comment - 17/Jun/08 07:38 AM
My inclination is that the Map behavior isn't widely used and was provided as a feature without any real requirement but if we think someone is relyign on this behavior then I guess we should leave it and document it.

Paul King added a comment - 17/Jun/08 05:41 PM
JavaDoc updated and Closure version added to allow non-flattening behavior for Maps if desired.