useFlatMap
诊断类别:lint/complexity/useFlatMap
¥Diagnostic Category: lint/complexity/useFlatMap
自从:v1.0.0
¥Since: v1.0.0
来源:
¥Sources:
-
与以下相同:
unicorn/prefer-array-flat-map
¥Same as:
unicorn/prefer-array-flat-map
-
与以下相同:
map_flatten
¥Same as:
map_flatten
提倡在 map().flat()
一起使用时使用 .flatMap()
。
¥Promotes the use of .flatMap()
when map().flat()
are used together.
¥Examples
¥Invalid
code-block.js:2:1 lint/complexity/useFlatMap FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The call chain .map().flat() can be replaced with a single .flatMap() call.
1 │ const array = [“split”, “the text”, “into words”];
> 2 │ array.map(sentence => sentence.split(’ ‘)).flat();
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3 │
ℹ Safe fix: Replace the chain with .flatMap().
1 1 │ const array = [“split”, “the text”, “into words”];
2 │ - array.map(sentence·=>·sentence.split(’·‘)).flat();
2 │ + array.flatMap(sentence·=>·sentence.split(’·’));
3 3 │
code-block.js:2:1 lint/complexity/useFlatMap FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The call chain .map().flat() can be replaced with a single .flatMap() call.
1 │ const array = [“split”, “the text”, “into words”];
> 2 │ array.map(sentence => sentence.split(’ ‘)).flat(1);
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3 │
ℹ Safe fix: Replace the chain with .flatMap().
1 1 │ const array = [“split”, “the text”, “into words”];
2 │ - array.map(sentence·=>·sentence.split(’·‘)).flat(1);
2 │ + array.flatMap(sentence·=>·sentence.split(’·’));
3 3 │
¥Valid
¥Related links