Created
October 18, 2018 13:24
-
-
Save tjeerdintveen/c76b03ec9526df59d8247873bd18c436 to your computer and use it in GitHub Desktop.
inspect as an extension on Sequence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Sequence { | |
public func inspect( | |
_ body: (Element) throws -> Void | |
) rethrows -> Self { | |
for element in self { | |
try body(element) | |
} | |
return self | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can add inspection in a transformation pipeline to see the values.
It's like forEach. Except that you can keep on going.
E.g.