[Accepted with revisions] SE-0187 “Introduce Sequence.filterMap(_:)”

Hi, Swift community! I apologize for the delay in reporting our decision here; between one holiday and the other, it took awhile for the core team to assemble a quorum to talk through this.

Proposal Link: swift-evolution/0187-introduce-filtermap.md at master · apple/swift-evolution · GitHub

The second review of SE-0187 “Introduce Sequence.filterMap(_:)” ran from November 15...20, 2017. The result of the first review was consensus to rename the method, and the purpose of the second review was to get more specific feedback on what the new name should be.

"filterMap" is a name with some precedent in other programming languages, especially functional ones, but some people felt strongly that the name was misleading because, as a combined operation, it wasn't quite a filter or a map. Of the alternatives, the one with the strongest support seemed to be "compactMap", which builds on the precedent of "compact", an operation from other languages (notably Ruby) which returns a copy of the input without nil values. Swift does not currently have such an operation, and in fact it is not currently possible to express it; nonetheless, the core team agrees that it would be a reasonable operation to add, and that "compactMap" is a good name for the operation.

Therefore, SE-0187 is accepted, with the revision that the new name be Sequence.compactMap(_:), and with the agreement that we will add Sequence.compact() when it is possible to do so.

Thank you all for your continued contributions to making Swift a better language.

John McCall
Review Manager

1 Like

Happy to hear that we went in this direction! Looking forward to the compact method as well.

Jarod

···

On Dec 19, 2017, 08:56 -0800, John McCall via swift-evolution <swift-evolution@swift.org>, wrote:

Hi, Swift community! I apologize for the delay in reporting our decision here; between one holiday and the other, it took awhile for the core team to assemble a quorum to talk through this.

Proposal Link: swift-evolution/0187-introduce-filtermap.md at master · apple/swift-evolution · GitHub

The second review of SE-0187 “Introduce Sequence.filterMap(_:)” ran from November 15...20, 2017. The result of the first review was consensus to rename the method, and the purpose of the second review was to get more specific feedback on what the new name should be.

"filterMap" is a name with some precedent in other programming languages, especially functional ones, but some people felt strongly that the name was misleading because, as a combined operation, it wasn't quite a filter or a map. Of the alternatives, the one with the strongest support seemed to be "compactMap", which builds on the precedent of "compact", an operation from other languages (notably Ruby) which returns a copy of the input without nil values. Swift does not currently have such an operation, and in fact it is not currently possible to express it; nonetheless, the core team agrees that it would be a reasonable operation to add, and that "compactMap" is a good name for the operation.

Therefore, SE-0187 is accepted, with the revision that the new name be Sequence.compactMap(_:), and with the agreement that we will add Sequence.compact() when it is possible to do so.

Thank you all for your continued contributions to making Swift a better language.

John McCall
Review Manager

I like `compact` as the basis for the name, but I hope the core team will consider whether the eventual nil-removal method should be called `compacting()`, and whether therefore this method should be called `compactingMap(_:)`. Prior art on the name `compact()` does exist, but I don't think it's strong enough to justify deviating from the API Guidelines.

I don't think we need a full review on this tiny issue; five minutes of the core team's time should more than suffice.

···

On Dec 19, 2017, at 8:56 AM, John McCall <rjmccall@apple.com> wrote:

Therefore, SE-0187 is accepted, with the revision that the new name be Sequence.compactMap(_:), and with the agreement that we will add Sequence.compact() when it is possible to do so.

--
Brent Royal-Gordon
Architechies

I disagree. Let’s not reopen what is settled. “Compact” can be a noun just
as “map” and “filter” can; as long as there are no in-place variants, there
can be no ambiguity.

···

On Tue, Dec 19, 2017 at 17:11 Brent Royal-Gordon via swift-evolution < swift-evolution@swift.org> wrote:

On Dec 19, 2017, at 8:56 AM, John McCall <rjmccall@apple.com> wrote:

Therefore, SE-0187 is *accepted*, with the *revision* that the new name
be Sequence.compactMap(_:), and with the agreement that we will add
Sequence.compact() when it is possible to do so.

I like `compact` as the basis for the name, but I hope the core team will
consider whether the eventual nil-removal method should be called
`compacting()`, and whether therefore this method should be called
`compactingMap(_:)`. Prior art on the name `compact()` does exist, but I
don't think it's strong enough to justify deviating from the API Guidelines.

I don't think we need a full review on this tiny issue; five minutes of
the core team's time should more than suffice.

--
Brent Royal-Gordon
Architechies

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

I agree with Brent. IMO we're firmly outside the domain of established terms-of-art here (Ruby notwithstanding).

···

On Dec 19, 2017, at 2:28 PM, Xiaodi Wu via swift-evolution <swift-evolution@swift.org> wrote:

I disagree. Let’s not reopen what is settled. “Compact” can be a noun just as “map” and “filter” can; as long as there are no in-place variants, there can be no ambiguity.
On Tue, Dec 19, 2017 at 17:11 Brent Royal-Gordon via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

On Dec 19, 2017, at 8:56 AM, John McCall <rjmccall@apple.com <mailto:rjmccall@apple.com>> wrote:

Therefore, SE-0187 is accepted, with the revision that the new name be Sequence.compactMap(_:), and with the agreement that we will add Sequence.compact() when it is possible to do so.

I like `compact` as the basis for the name, but I hope the core team will consider whether the eventual nil-removal method should be called `compacting()`, and whether therefore this method should be called `compactingMap(_:)`. Prior art on the name `compact()` does exist, but I don't think it's strong enough to justify deviating from the API Guidelines.

I don't think we need a full review on this tiny issue; five minutes of the core team's time should more than suffice.

meh, on second though, "map" is already right there. I'm ambivalent now; sorry I weighed in.

···

On Dec 19, 2017, at 3:42 PM, Dave Abrahams via swift-evolution <swift-evolution@swift.org> wrote:

On Dec 19, 2017, at 2:28 PM, Xiaodi Wu via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

I disagree. Let’s not reopen what is settled. “Compact” can be a noun just as “map” and “filter” can; as long as there are no in-place variants, there can be no ambiguity.
On Tue, Dec 19, 2017 at 17:11 Brent Royal-Gordon via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

On Dec 19, 2017, at 8:56 AM, John McCall <rjmccall@apple.com <mailto:rjmccall@apple.com>> wrote:

Therefore, SE-0187 is accepted, with the revision that the new name be Sequence.compactMap(_:), and with the agreement that we will add Sequence.compact() when it is possible to do so.

I like `compact` as the basis for the name, but I hope the core team will consider whether the eventual nil-removal method should be called `compacting()`, and whether therefore this method should be called `compactingMap(_:)`. Prior art on the name `compact()` does exist, but I don't think it's strong enough to justify deviating from the API Guidelines.

I don't think we need a full review on this tiny issue; five minutes of the core team's time should more than suffice.

I agree with Brent. IMO we're firmly outside the domain of established terms-of-art here (Ruby notwithstanding).

I don't think anybody wants a big discussion out of this, but if there's a chance that the name will be further revised, then I agree with Nevin, the solo "compacted" is a more appropriate term than "compacting" here. Compacting needs an grammatical object to apply to, so if we wanted to use that form, "compactingElements" would be the proper way to phrase it.

"compactingMap" works, because the map operation is being compacted. But "compactedMap" also works, because it's a compacted form of the map operation.

So if we want to revise the naming, I would suggest "compacted" and "compactedMap". But I think the accepted naming is fine as well, and we should avoid "compacting".

Jarod

···

On Dec 19, 2017, 15:52 -0800, Nevin Brackett-Rozinsky via swift-evolution <swift-evolution@swift.org>, wrote:

If we’re bikeshedding the verb tense then “compactMap” sounds right to me, and adding “ing” would be needlessly verbose.

For the non-mapping version, I’d lean toward “compacted”. However, we could also postpone the debate over its spelling until such time as we are actually ready to introduce it.

Nevin

> On Tue, Dec 19, 2017 at 6:42 PM, Dave Abrahams via swift-evolution <swift-evolution@swift.org> wrote:
> >
> >
> > > On Dec 19, 2017, at 2:28 PM, Xiaodi Wu via swift-evolution <swift-evolution@swift.org> wrote:
> > >
> > > I disagree. Let’s not reopen what is settled. “Compact” can be a noun just as “map” and “filter” can; as long as there are no in-place variants, there can be no ambiguity.
> > > > On Tue, Dec 19, 2017 at 17:11 Brent Royal-Gordon via swift-evolution <swift-evolution@swift.org> wrote:
> > > > > > On Dec 19, 2017, at 8:56 AM, John McCall <rjmccall@apple.com> wrote:
> > > > > >
> > > > > > Therefore, SE-0187 is accepted, with the revision that the new name be Sequence.compactMap(_:), and with the agreement that we will add Sequence.compact() when it is possible to do so.
> > > > >
> > > > > I like `compact` as the basis for the name, but I hope the core team will consider whether the eventual nil-removal method should be called `compacting()`, and whether therefore this method should be called `compactingMap(_:)`. Prior art on the name `compact()` does exist, but I don't think it's strong enough to justify deviating from the API Guidelines.
> > > > >
> > > > > I don't think we need a full review on this tiny issue; five minutes of the core team's time should more than suffice.
> >
> > I agree with Brent. IMO we're firmly outside the domain of established terms-of-art here (Ruby notwithstanding).
> >
> > _______________________________________________
> > swift-evolution mailing list
> > swift-evolution@swift.org
> > https://lists.swift.org/mailman/listinfo/swift-evolution
> >

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

If we’re bikeshedding the verb tense then “compactMap” sounds right to me,
and adding “ing” would be needlessly verbose.

For the non-mapping version, I’d lean toward “compacted”. However, we could
also postpone the debate over its spelling until such time as we are
actually ready to introduce it.

Nevin

···

On Tue, Dec 19, 2017 at 6:42 PM, Dave Abrahams via swift-evolution < swift-evolution@swift.org> wrote:

On Dec 19, 2017, at 2:28 PM, Xiaodi Wu via swift-evolution < > swift-evolution@swift.org> wrote:

I disagree. Let’s not reopen what is settled. “Compact” can be a noun just
as “map” and “filter” can; as long as there are no in-place variants, there
can be no ambiguity.
On Tue, Dec 19, 2017 at 17:11 Brent Royal-Gordon via swift-evolution < > swift-evolution@swift.org> wrote:

On Dec 19, 2017, at 8:56 AM, John McCall <rjmccall@apple.com> wrote:

Therefore, SE-0187 is *accepted*, with the *revision* that the new name
be Sequence.compactMap(_:), and with the agreement that we will add
Sequence.compact() when it is possible to do so.

I like `compact` as the basis for the name, but I hope the core team will
consider whether the eventual nil-removal method should be called
`compacting()`, and whether therefore this method should be called
`compactingMap(_:)`. Prior art on the name `compact()` does exist, but I
don't think it's strong enough to justify deviating from the API Guidelines.

I don't think we need a full review on this tiny issue; five minutes of
the core team's time should more than suffice.

I agree with Brent. IMO we're firmly outside the domain of established
terms-of-art here (Ruby notwithstanding).

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Yes. If we’re fussing over the verb tense, “compacted” is clearly correct. Where did “compacting” come from? The API guidelines state:

Prefer to name the nonmutating variant using the verb’s past participle (usually appending “ed”).

…and (emphasis added):

When adding “ed” _is not grammatical because the verb has a direct object_, name the nonmutating variant using the verb’s present participle, by appending “ing.”

Thus “joined” and “sorted” — also no-args methods where the verb has no direct object.

BUT

The existing methods “filter” and “reduce” seem the nearest peers to the proposed “compact,” and we do not call them “filtered” and “reduced.” Those are the methods with which the new one should maintain consistency.

P

···

On Dec 19, 2017, at 5:52 PM, Nevin Brackett-Rozinsky via swift-evolution <swift-evolution@swift.org> wrote:

If we’re bikeshedding the verb tense then “compactMap” sounds right to me, and adding “ing” would be needlessly verbose.

For the non-mapping version, I’d lean toward “compacted”. However, we could also postpone the debate over its spelling until such time as we are actually ready to introduce it.

Nevin

On Tue, Dec 19, 2017 at 6:42 PM, Dave Abrahams via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

On Dec 19, 2017, at 2:28 PM, Xiaodi Wu via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

I disagree. Let’s not reopen what is settled. “Compact” can be a noun just as “map” and “filter” can; as long as there are no in-place variants, there can be no ambiguity.
On Tue, Dec 19, 2017 at 17:11 Brent Royal-Gordon via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

On Dec 19, 2017, at 8:56 AM, John McCall <rjmccall@apple.com <mailto:rjmccall@apple.com>> wrote:

Therefore, SE-0187 is accepted, with the revision that the new name be Sequence.compactMap(_:), and with the agreement that we will add Sequence.compact() when it is possible to do so.

I like `compact` as the basis for the name, but I hope the core team will consider whether the eventual nil-removal method should be called `compacting()`, and whether therefore this method should be called `compactingMap(_:)`. Prior art on the name `compact()` does exist, but I don't think it's strong enough to justify deviating from the API Guidelines.

I don't think we need a full review on this tiny issue; five minutes of the core team's time should more than suffice.

I agree with Brent. IMO we're firmly outside the domain of established terms-of-art here (Ruby notwithstanding).

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

I lean slightly towards "but they already have been through this", but given that the core term is "compact" and it is secondary to map, then I think `mapCompacting` is superior:

* It mirrors the process better (apply function, then decide whether to include or exclude the result)
* It prefers `compacting` as Brent points out, supporting the Swift API Guidelines
* It uses the term of art `map` consistently with this preferred term.
* It places the two names closer together in autocomplete

-- E, hiding the bikeshed paintbrush behind her back

···

On Dec 19, 2017, at 4:42 PM, Dave Abrahams via swift-evolution <swift-evolution@swift.org> wrote:

On Dec 19, 2017, at 2:28 PM, Xiaodi Wu via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

I disagree. Let’s not reopen what is settled. “Compact” can be a noun just as “map” and “filter” can; as long as there are no in-place variants, there can be no ambiguity.
On Tue, Dec 19, 2017 at 17:11 Brent Royal-Gordon via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

On Dec 19, 2017, at 8:56 AM, John McCall <rjmccall@apple.com <mailto:rjmccall@apple.com>> wrote:

Therefore, SE-0187 is accepted, with the revision that the new name be Sequence.compactMap(_:), and with the agreement that we will add Sequence.compact() when it is possible to do so.

I like `compact` as the basis for the name, but I hope the core team will consider whether the eventual nil-removal method should be called `compacting()`, and whether therefore this method should be called `compactingMap(_:)`. Prior art on the name `compact()` does exist, but I don't think it's strong enough to justify deviating from the API Guidelines.

I don't think we need a full review on this tiny issue; five minutes of the core team's time should more than suffice.

I agree with Brent. IMO we're firmly outside the domain of established terms-of-art here (Ruby notwithstanding).

+1 for .mapCompacting

···

On Dec 21, 2017, at 8:49 PM, Erica Sadun via swift-evolution <swift-evolution@swift.org> wrote:

On Dec 19, 2017, at 4:42 PM, Dave Abrahams via swift-evolution <swift-evolution@swift.org> wrote:

On Dec 19, 2017, at 2:28 PM, Xiaodi Wu via swift-evolution <swift-evolution@swift.org> wrote:

I disagree. Let’s not reopen what is settled. “Compact” can be a noun just as “map” and “filter” can; as long as there are no in-place variants, there can be no ambiguity.
On Tue, Dec 19, 2017 at 17:11 Brent Royal-Gordon via swift-evolution <swift-evolution@swift.org> wrote:

On Dec 19, 2017, at 8:56 AM, John McCall <rjmccall@apple.com> wrote:

Therefore, SE-0187 is accepted, with the revision that the new name be Sequence.compactMap(_:), and with the agreement that we will add Sequence.compact() when it is possible to do so.

I like `compact` as the basis for the name, but I hope the core team will consider whether the eventual nil-removal method should be called `compacting()`, and whether therefore this method should be called `compactingMap(_:)`. Prior art on the name `compact()` does exist, but I don't think it's strong enough to justify deviating from the API Guidelines.

I don't think we need a full review on this tiny issue; five minutes of the core team's time should more than suffice.

I agree with Brent. IMO we're firmly outside the domain of established terms-of-art here (Ruby notwithstanding).

I lean slightly towards "but they already have been through this", but given that the core term is "compact" and it is secondary to map, then I think `mapCompacting` is superior:

* It mirrors the process better (apply function, then decide whether to include or exclude the result)
* It prefers `compacting` as Brent points out, supporting the Swift API Guidelines
* It uses the term of art `map` consistently with this preferred term.
* It places the two names closer together in autocomplete

-- E, hiding the bikeshed paintbrush behind her back
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution