2.0.0 β’ Published 1 year ago
@putout/plugin-apply-flat-map v2.0.0
@putout/plugin-apply-flat-map
The
flatMap()
method returns a new array formed by applying a given callback function to each element of the array, and then flattening the result by one level. It is identical to amap()
followed by aflat()
of depth 1 (arr.map(...args).flat()
), but slightly more efficient than calling those two methods separately.(c) MDN
πPutout plugin adds ability to apply flatMap()
. Check out in πPutout Editor.
Install
npm i @putout/plugin-apply-flat-map
Rule
{
"rules": {
"apply-flat-map": "on"
}
}
β Example of incorrect code
array.map(getId).flat();
β Example of correct code
array.flatMap(getId);
Comparison
Linter | Rule | Fix |
---|---|---|
π Putout | apply-flat-map | β |
β£ ESLint | unicorn/prefer-flat-map | β |
π Rome | useFlatMap | β |
License
MIT