2.0.0 β€’ Published 1 year ago

@putout/plugin-apply-flat-map v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@putout/plugin-apply-flat-map NPM version

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 a map() followed by a flat() 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

LinterRuleFix
🐊 Putoutapply-flat-mapβœ…
⏣ ESLintunicorn/prefer-flat-mapβœ…
πŸ› RomeuseFlatMapβœ…

License

MIT