Skip to content

Files

Latest commit

 

History

History
21 lines (12 loc) · 528 Bytes

UseCollectMany.md

File metadata and controls

21 lines (12 loc) · 528 Bytes

Pattern: Use of collect.flatten()

Issue: -

Description

In many cases collectMany() yields the same result as collect.flatten(). It is easier to understand and more clearly conveys the intent.

Example of violations:

def l = [1, 2, 3, 4]

l.collect{ [it, it*2] }.flatten() // suboptimal

l.collectMany{ [it, it*2] }       // same functionality, better readability

Further Reading