Skip to content

Instantly share code, notes, and snippets.

@Julioacarrettoni
Last active December 22, 2015 20:57
Show Gist options
  • Save Julioacarrettoni/fd31c5b35d3eaf5154e4 to your computer and use it in GitHub Desktop.
Save Julioacarrettoni/fd31c5b35d3eaf5154e4 to your computer and use it in GitHub Desktop.
Playing with lazy collections and maps and flats and stuff… (and getting really really confused)
let array = [1, 2, 3, 4, 5, 6]
array.map { (value) -> [Int] in
print(value)
return [value]
}
array.lazy.map { (value) -> [Int] in
print("value: \(value)")
return [value+1]
}.first
array.lazy.flatMap { (value) -> [Int]? in
print("value: \(value)")
return value > 3 ? [value] : nil
}.first
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment