Feature #19787
Updated by joshuay03 (Joshua Young) over 1 year ago
I would like to propose a collection of new methods, `Enumerable#uniq_map`, `Enumerable::Lazy#uniq_map`, `Array#uniq_map` and `Array#uniq_map!`. TL;DR: It's a drop in replacement for `.map { ... }.uniq`, with (hopefully) better performance. I've quite often had to map over an array and get its unique elements. It occurred to me when doing so recently that Ruby doesn't have a short form method for doing that, similar to how `.flat_map `flat_map { ... }` replaces `.map { ... }.flatten` and `.filter_map `filter_map { ... }` replaces `.map { ... }.compact` (with minor differences). I think these new methods could be beneficial both in terms of better performance and writing more succinct code. I've I have already got a draft PR up with some initial benchmarks in the description: https://github.com/ruby/ruby/pull/8140.