Inspectopedia
 
2024.3

'associate' can be replaced with 'associateBy' or 'associateWith'

Info
New
Last modified: 03 December 2024

Reports calls to associate() and associateTo() that can be replaced with associateBy() or associateWith().

Both functions accept a transformer function applied to elements of a given sequence or collection (as a receiver). The pairs are then used to build the resulting Map.

Given the transformer refers to it, the associate[To]() call can be replaced with more performant associateBy() or associateWith().

Examples:

After the quick-fix is applied: