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

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

Example:


  class Entity(val key: String, val value: String)

  fun getValues(lines: List<String>) = lines
      .filter { it.isNotEmpty() }
      .map { it.split(',', limit = 2) }
      .filter { it.size == 2 }
      .map { Entity(it[0], it[1]) }

A quick-fix is suggested to wrap call chain into asSequence() and toList():


  class Entity(val key: String, val value: String)

  fun getValues(lines: List<String>) = lines
      .asSequence()
      .filter { it.isNotEmpty() }
      .map { it.split(',', limit = 2) }
      .filter { it.size == 2 }
      .map { Entity(it[0], it[1]) }
      .toList()