[swift-evolution] [Pitch] Add an all algorithm to Sequence
Ricardo Parada
rparada at mac.com
Sat Apr 1 13:32:06 CDT 2017
Hi all,
I think that when used without the argument label it is not as clear what it does. For example:
nums.all { $0 % 2 == 0 }
can be interpreted as give me all the even elements.
So if the argument label were to be left out, then I would rename it. Some options:
nums.allSatisfy { $0 % 2 == 0 } // All are even
nums.allMatch { $0 % 2 == 0 } // All are even
nums.membersSatisfy { $0 % 2 == 0 } // All are even
nums.membersMatch { $0 % 2 == 0 } // All are even
nums.elementsSatisfy { $0 % 2 == 0 } // All are even
nums.elementsMatch { $0 % 2 == 0 } // All are even
Personally, I think I like nums.allMatch { $0 % 2 == 0 }.
> On Apr 1, 2017, at 1:58 PM, 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/d5c0a168/attachment.html>
More information about the swift-evolution
mailing list