Call chain on collection could be converted into 'Sequence' to improve performance

Last modified: 03 December 2024

Reports call chain on a Collection that should be converted into Sequence.

Each Collection transforming function (such as map() or filter()) creates a new Collection (typically List or Set) under the hood. In case of multiple consequent calls, and a huge number of items in Collection, memory traffic might be significant. In such a case, using Sequence is preferred.

Example:

The quick-fix wraps call chain into asSequence() and toList():