I'm proposing a new extension method on SequenceType called find(). It's 
similar to CollectionType.indexOf() except it returns the element:

extension SequenceType {

/// 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
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to