Why not add to the library:
extension Sequence {
func forEach(_ eacher: (Iterator.Element) throws -> Void, elser: ()
throws -> Void) rethrows {
var hasIterated = false
for element in self {
hasIterated = true
try eacher(element)
}
guard hasIterated else {
try elser()
return
}
}
}
On Fri, 3 Feb 2017 at 8:33 pm, Jeremy Pereira via swift-users <
[email protected]> wrote:
>
> > On 2 Feb 2017, at 20:12, Erica Sadun via swift-users <
> [email protected]> wrote:
> >
> > I've taken this over to Swift Users from Swift Evolution.
> >
> > I think you'd want to handle the exceptional case first,
>
> Although it is the way I would do it for an array, sometimes you don’t
> know that a sequence is empty until after you have iterated it.
>
>
> _______________________________________________
> swift-users mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-users
>
--
-- Howard.
_______________________________________________
swift-users mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-users