class Ameba::Rule::Performance::FlattenAfterMap
- Ameba::Rule::Performance::FlattenAfterMap
- Ameba::Rule::Performance::Base
- Ameba::Rule::Base
- Reference
- Object
Overview
This rule is used to identify usage of flatten
calls that follow map
.
For example, this is considered inefficient:
%w[Alice Bob].map(&.chars).flatten
And can be written as this:
%w[Alice Bob].flat_map(&.chars)
YAML configuration example:
Performance/FlattenAfterMap:
Enabled: true
Included Modules
- YAML::Serializable
- YAML::Serializable::Strict
Defined in:
ameba/rule/performance/flatten_after_map.crConstant Summary
-
FLATTEN_NAME =
"flatten"
-
MAP_NAME =
"map"
-
MSG =
"Use `flat_map {...}` instead of `map {...}.flatten`"
Constructors
-
.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
This rule is used to identify usage of
flatten
calls that followmap
. -
.new(config = nil)
This rule is used to identify usage of
flatten
calls that followmap
.
Instance Method Summary
- #description : String
- #description=(description : String)
- #enabled : Bool
- #enabled=(enabled : Bool)
- #excluded : Array(String) | Nil
- #excluded=(excluded : Array(String) | Nil)
- #severity : Ameba::Severity
- #severity=(severity : Ameba::Severity)
- #test(source, node : Crystal::Call)
- #test(source)
Instance methods inherited from class Ameba::Rule::Performance::Base
catch(source : Source)
catch
Constructor methods inherited from class Ameba::Rule::Performance::Base
new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)new(config = nil) new
Instance methods inherited from class Ameba::Rule::Base
==(other)
==,
catch(source : Source)
catch,
excluded?(source)
excluded?,
group
group,
hash
hash,
name
name,
special?
special?,
test(source : Source, node : Crystal::ASTNode, *opts)test(source : Source) test
Class methods inherited from class Ameba::Rule::Base
parsed_doc
parsed_doc
Constructor Detail
def self.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
#
This rule is used to identify usage of flatten
calls that follow map
.
For example, this is considered inefficient:
%w[Alice Bob].map(&.chars).flatten
And can be written as this:
%w[Alice Bob].flat_map(&.chars)
YAML configuration example:
Performance/FlattenAfterMap:
Enabled: true
def self.new(config = nil)
#
This rule is used to identify usage of flatten
calls that follow map
.
For example, this is considered inefficient:
%w[Alice Bob].map(&.chars).flatten
And can be written as this:
%w[Alice Bob].flat_map(&.chars)
YAML configuration example:
Performance/FlattenAfterMap:
Enabled: true