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

André Videla andre.videla at gmail.com
Sat Apr 1 13:11:35 CDT 2017


I agree that if “contains” has its place in the standard library, so does “all”

I also regularly use the extension

func forAll(suchThat predicate: (Element) -> Bool) -> Bool

which I use like so

[0,1,2,3,4].forAll(suchThat: isEven)

[0,1,2,3,4].forAll { $0 < 5}


> On 1 Apr 2017, at 19:58, Nevin Brackett-Rozinsky via swift-evolution <swift-evolution at swift.org> wrote:
> 
> If indeed “all(equal:)” is rarely needed, then perhaps it is best to leave it out *and also* leave out the argument label from “all(matching:)”. Then the signature would be similar to,
> 
> func all(_ predicate: (Element)->Bool) -> Bool
> 
> and the points-of-use would look like:
> 
> nums.all( isEven )
> nums.all{ $0 == 9 }
> nums.all{ n in n*n < 2 }
> 
> Nevin
> _______________________________________________
> 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/20170401/acb71bab/attachment.html>


More information about the swift-evolution mailing list