Skip to content

Instantly share code, notes, and snippets.

@worchyld
Created August 6, 2017 07:31
Show Gist options
  • Save worchyld/6c7d201ac1b92f3e7efaa2416ff30176 to your computer and use it in GitHub Desktop.
Save worchyld/6c7d201ac1b92f3e7efaa2416ff30176 to your computer and use it in GitHub Desktop.
Create 10 decks in a functional for-loop
// Swift 3
struct Deck {
var name: String
}
// usual way;
var decks : [Deck] = [Deck]()
for idx in 1...10 {
decks.append( Deck.init(name: "#\(idx)") )
}
// functional way
let decks = (1...10).enumerated().map({ (offset, element) in
return (Deck.init(name: "Deck.\(offset)"))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment