Created
August 6, 2017 07:31
-
-
Save worchyld/6c7d201ac1b92f3e7efaa2416ff30176 to your computer and use it in GitHub Desktop.
Create 10 decks in a functional for-loop
This file contains 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
// 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