Last active
June 29, 2017 04:24
-
-
Save sumitokamoi/ac82416fb9bb6892656a8595e7b53bf2 to your computer and use it in GitHub Desktop.
クロージャ内で変数をキャプチャして使う
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
var nums = (10...19) | |
let result = nums.enumerated().flatMap { [count = nums.count, x = 10] (offset: Int, element: Int) -> [Int] in | |
if offset < count / 2 { | |
return [] | |
} | |
return [element, element-x] | |
} | |
print(result) // [15, 5, 16, 6, 17, 7, 18, 8, 19, 9] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment