Last active
November 24, 2017 04:32
-
-
Save leilee/61cda8c2bc737ed3b30dd3f2ca8a29b3 to your computer and use it in GitHub Desktop.
#Foundation
This file contains hidden or 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 Int { | |
func times(_ closure: (Int) throws -> Void) rethrows { | |
try (0...self).forEach { | |
try closure($0) | |
} | |
} | |
@discardableResult | |
func times<T>(_ closure: (Int) throws -> T) rethrows -> [T] { | |
var result: [T] = [] | |
try (0..<self).forEach { | |
try result.append(closure($0)) | |
} | |
return result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment