[swift-evolution] [Pitch] Add an all algorithm to Sequence

Xiaodi Wu xiaodi.wu at gmail.com
Sun Apr 2 01:55:54 CDT 2017


Given that most popular languages seem to use the word "every" or "all" in
the name of their analogous functions, I think it's very valuable to honor
that legitimate user expectation if at all possible. I do believe the Swift
API naming guidelines are not so rigid as to prohibit such a name.

While accurate, "onlyContains" lacks that familiarity. (A Google search of
"onlyContains" turns up: "Study finds Subway's chicken only contains about
50 percent.")


On Sun, Apr 2, 2017 at 12:57 AM, Rien <Rien at balancingrock.nl> wrote:

>
> > On 02 Apr 2017, at 07:51, Karl Wagner via swift-evolution <
> swift-evolution at swift.org> wrote:
> >
> > Given the relationship to contains, why not keep it simple and go with:
> >
> > onlyContains(_ element:)
> > onlyContains(_ matching:)
> >
> > [9, 9, 9, 9, 9].onlyContains(9) // true
> > [1, 2, 3, 2, 3].onlyContains { $0 < 3 } // false
> >
> > - Karl
>
> IMO, we have a winner!
>
> Rien.
>
> >
> >> On 1 Apr 2017, at 10:47, Xiaodi Wu via swift-evolution <
> swift-evolution at swift.org> wrote:
> >>
> >> On Sat, Apr 1, 2017 at 3:40 AM, David Hart via swift-evolution <
> swift-evolution at swift.org> wrote:
> >>
> >> On 1 Apr 2017, at 09:50, Brandon Trussell <brandon2k3 at gmail.com> wrote:
> >>
> >>> I agree that based on the method name, I thought a collection would be
> returned.
> >>
> >> Now that I think more about it, I think you're right. It is confusing.
> Perhaps:
> >>
> >> allAre(equalTo: )
> >> allAre(matching: )
> >>
> >> Well, if we're going to go full stdlib naming guidelines, shouldn't
> they be--
> >>
> >> ```
> >> areAll(equalTo:)
> >> areAll(matching:)
> >> ```
> >>
> >>> On Sat, Apr 1, 2017 at 12:36 AM, David Hart via swift-evolution <
> swift-evolution at swift.org> wrote:
> >>>
> >>>
> >>> > On 1 Apr 2017, at 06:02, Will Stanton via swift-evolution <
> swift-evolution at swift.org> wrote:
> >>> >
> >>> > +1 to adding, but the name `all` suggests (to me) the return of
> another sequence, not a Bool.
> >>>
> >>> I'm not too concerned because the mandatory labels makes it clear.
> >>>
> >>> > Perhaps the function name should be question-like?
> >>> >
> >>> > Suggesting: `membersSatisfy(condition:)` or `allSatisfy(condition:)`
> or maybe even just `satisfies(condition:)`
> >>> > The question-like modifier/verb is necessary to suggest a Bool and
> IMO not a needless word.
> >>> >
> >>> > Regards,
> >>> > Will Stanton
> >>> >
> >>> >> On Mar 31, 2017, at 11:28, Ben Cohen via swift-evolution <
> swift-evolution at swift.org> wrote:
> >>> >>
> >>> >> Hopefully non-controversial, aside from the naming of the method
> and arguments, about which controversy abounds
> >>> >
> >>> > _______________________________________________
> >>> > swift-evolution mailing list
> >>> > swift-evolution at swift.org
> >>> > https://lists.swift.org/mailman/listinfo/swift-evolution
> >>>
> >>> _______________________________________________
> >>> swift-evolution mailing list
> >>> swift-evolution at swift.org
> >>> https://lists.swift.org/mailman/listinfo/swift-evolution
> >>>
> >>>
> >>>
> >>> --
> >>> Brandon
> >>
> >> _______________________________________________
> >> swift-evolution mailing list
> >> swift-evolution at swift.org
> >> https://lists.swift.org/mailman/listinfo/swift-evolution
> >>
> >>
> >> _______________________________________________
> >> swift-evolution mailing list
> >> swift-evolution at swift.org
> >> https://lists.swift.org/mailman/listinfo/swift-evolution
> >
> > _______________________________________________
> > swift-evolution mailing list
> > swift-evolution at swift.org
> > https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170402/1029db18/attachment.html>


More information about the swift-evolution mailing list