Good thought, but I doubt such a method would pull its own weight. -Kevin Ballard
On Wed, Dec 30, 2015, at 04:24 PM, Nevin Brackett-Rozinsky wrote: > Is it worth considering a version that returns a tuple of (index, > element) ? > > Nevin > > > On Tue, Dec 29, 2015 at 9:40 PM, Keith Smiley via swift-evolution <swift- > [email protected]> wrote: >> +1. We've added an extension for this and find it very useful. On >> Tue, Dec 29, 2015 at 18:38 Kevin Ballard via swift-evolution <swift- >> [email protected]> 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 >>> >>> >>> _______________________________________________ >>> swift-evolution mailing list >>> [email protected] >>> https://lists.swift.org/mailman/listinfo/swift-evolution >> >> _______________________________________________ >> swift-evolution mailing list >> [email protected] >> https://lists.swift.org/mailman/listinfo/swift-evolution >>
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
