Yeah, seeing those two side-by-side indicates that perhaps firstMap
isn't the best name. I picked it because of its symmetry with first(where:)
and compactMap(_:)
.
I believe this is worth adding to the Standard Library, because it meets The Law of Soroush:
If an extension meets any one of the following four criteria, it deserves to exist:
- Does it increase expressivity?
- Does it decrease noise?
- Does it include a performance optimization?
- Does it belong on every instance of the type?