You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This new cop would be a twin of Style/MapToHash, but for .to_set:
# badlist.map{ |x| x + 1}.to_setlist.collect(&:to_s).to_set# goodlist.to_set{ |x| x + 1}list.to_set(&:to_s)
Performance-wise, both ways appear to be identical (although there may be some additional memory benefit in avoiding the intermediate .map since sets are implemented using hashes internally 🤷♂️)
The text was updated successfully, but these errors were encountered:
Fixesrubocop#11339.
This PR adds new `Style/MapToSet` cop
This cop looks for uses of `map.to_set` or `collect.to_set` that could be
written with just `to_set`. It is unsafe, as it can produce false positives
if the receiver is not an `Enumerable`.
```ruby
# bad
something.map { |i| i * 2 }.to_set
# good
something.to_set { |i| i * 2 }
# bad
[1, 2, 3].collect { |i| i.to_s }.to_set
# good
[1, 2, 3].to_set { |i| i.to_s }
```
Fixes#11339.
This PR adds new `Style/MapToSet` cop
This cop looks for uses of `map.to_set` or `collect.to_set` that could be
written with just `to_set`. It is unsafe, as it can produce false positives
if the receiver is not an `Enumerable`.
```ruby
# bad
something.map { |i| i * 2 }.to_set
# good
something.to_set { |i| i * 2 }
# bad
[1, 2, 3].collect { |i| i.to_s }.to_set
# good
[1, 2, 3].to_set { |i| i.to_s }
```
This new cop would be a twin of Style/MapToHash, but for
.to_set
:Performance-wise, both ways appear to be identical (although there may be some additional memory benefit in avoiding the intermediate
.map
since sets are implemented using hashes internally 🤷♂️)The text was updated successfully, but these errors were encountered: