class Ameba::Rule::Performance::FlattenAfterMap

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

Defined in:

ameba/rule/performance/flatten_after_map.cr

Constant Summary

FLATTEN_NAME = "flatten"
MAP_NAME = "map"
MSG = "Use `flat_map {...}` instead of `map {...}.flatten`"

Constructors

Instance Method Summary

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

[View source]

Instance Method Detail

def description : String #

def description=(description : String) #

def enabled : Bool #

def enabled=(enabled : Bool) #

def excluded : Array(String) | Nil #

def excluded=(excluded : Array(String) | Nil) #

def severity : Ameba::Severity #

def severity=(severity : Ameba::Severity) #

def test(source, node : Crystal::Call) #

[View source]
def test(source) #

[View source]