Issue #19787 has been reported by joshuay03 (Joshua Young).
----------------------------------------
Feature #19787: Add Enumerable#uniq_map, Enumerable::Lazy#uniq_map, Array#uniq_map and
Array#uniq_map!
https://bugs.ruby-lang.org/issues/19787
* Author: joshuay03 (Joshua Young)
* Status: Open
* Priority: Normal
----------------------------------------
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 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 { ... }` replaces `.map { ... }.flatten` and `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 have already got a draft PR up with some initial benchmarks in the description:
https://github.com/ruby/ruby/pull/8140.
--
https://bugs.ruby-lang.org/