menu

needless-collect

Disallow materializing an Iterator before a terminal operation

Materializing an Iterator before a terminal operation allocates storage for values that are immediately discarded. Instead, you SHOULD apply the terminal operation to the Iterator directly.

Materialization may intentionally isolate the terminal operation from later mutations, so the rewrite requires review.

Reported

1function length(values: Iterator<int32>): isize {2    return values.toArray().length;3}

Accepted

1function length(values: Iterator<int32>): isize {2    return values.count();3}