Software Design/Transform collection declaratively

Checklist questions:
 * Is it possible to transform or populate a collection or an array declaratively rather than in an imperative loop?
 * Is it possible to find or compute some result while iterating a collection with a declarative operation rather than an imperative loop?

The technologies which facilitate declarative computations on collections include:
 * LINQ in C#
 * Streams in Java
 * List comprehensions, generator expressions, and some functions from the  module in Python

Why
It's harder to make a mistake in a declarative or functional transformation than in an imperative loop because less (or none) additional variables are defined in the transformation and each of them is scoped to its anonymous function without interfering with other variables.

The semantics of a declarative pipeline may be more apparent because they refer to library symbols such named like "sum", "map", "where", "collect", "findFirst", etc. which identify the logical operation being applied. On the other hand, with collection transformation in an imperative loop, readers have to read the whole loop and recognize the logical operation being applied by the loop pattern, which puts cognitive load on them.

Functional collection processing usually requires less code than imperative. Functional processing is also often clearer than imperative processing because the former is free of boilerplate code such as a declaration of a loop variable and references to a collection element by index. Since functional collection transformation is free of low-level details about how to iterate the collection, it makes the definition of the collection and the processing logic looser coupled.

Declarative computations over a collection automatically ensure following the practice of not doing several collection transformations in a single loop.

Why not
It may be harder to debug declarative collection computations than equivalent imperative loops.

Functional collection transformation pipeline may be less efficient than an equivalent imperative code. Even when the performance difference between optimally written functional and imperative versions is not significant, it might be easy to make a performance bug in a declarative pipeline which would lead to unnecessary materialization of intermediate collection views. For example, in Kotlin, this is sometimes a matter of forgetting  call in the beginning of a pipeline.

Related

 * Don't mingle several collection transformations in a single loop