Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. extension Array {
  2.  
  3. /// A `forEach` that performs the next element after calling continuousHandler
  4. ///
  5. /// - Parameter body: allows calling the next element
  6. func forEachAsync(body: @escaping (_ element: Element, _ continuousHandler: @escaping () -> Void) -> Void) {
  7. var main: ((Int, Int) -> Void)? = nil
  8. main = { index, count in
  9. if index >= count {
  10. return
  11. }
  12.  
  13. body(self[index]) {
  14. main?(index + 1, count)
  15. }
  16. }
  17. main?(0, count)
  18. }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement