Skip to content

Improvement for Performance/MapCompact #497

Description

@ydakuka

Describe

# bad
enum.filter_map { |i| i + 1 if i.even? }.compact
# good
enum.filter_map { |i| i + 1 if i.even? }


# bad
enum&.filter_map { |i| i + 1 if i.even? }&.compact
# good
enum&.filter_map { |i| i + 1 if i.even? }

Rubocop

1.74.0 (using Parser 3.3.7.1, rubocop-ast 1.38.1, analyzing as Ruby 2.7, running on ruby 2.7.8) [x86_64-linux]
  - rubocop-capybara 2.22.1
  - rubocop-factory_bot 2.27.1
  - rubocop-migration 0.7.0
  - rubocop-performance 1.24.0
  - rubocop-rails 2.30.3
  - rubocop-rake 0.7.1
  - rubocop-rspec 3.5.0
  - rubocop-rspec_rails 2.31.0
  - rubocop-thread_safety 1.74.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions