[swift-evolution] Proposal: Add function SequenceType.find()
Kevin Ballard
kevin at sb.org
Sat Jan 9 18:58:45 CST 2016
Proposal PR submitted asĀ https://github.com/apple/swift-evolution/pull/94
-Kevin Ballard
On Tue, Dec 29, 2015, at 06:38 PM, Kevin Ballard wrote:
> I'm proposing a new extension method on SequenceType called find().
> It's similar to CollectionType.indexOf() except it returns the
> element:
>
> extensionSequenceType {
> /// Returns the first element where `predicate` returns `true`,
> or `nil`
> /// if such value is not found.
> public func find(@noescape predicate: (Self.Generator.Element) throws
> -> Bool) rethrows -> Self.Generator.Element? {
> for elt in self {
> if try predicate(elt) {
> return elt
> }
> }
> return nil
> }
> }
>
> -Kevin Ballard
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160109/602c5058/attachment.html>
More information about the swift-evolution
mailing list