Created
May 11, 2020 13:39
-
-
Save swavkulinski/d2e2ff0116fb35d7458a112d963326ae to your computer and use it in GitHub Desktop.
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
void main() { | |
// an array is a collection of objects | |
var dance = [Moves.LEFT,Moves.RIGHT,Moves.JUMP,]; | |
print('${dance[0]}'); | |
for (var move in dance) { | |
print('$move'); | |
} | |
print ('==================================='); | |
// a map is a collection of keys and values | |
var moveCost = { | |
Moves.LEFT: 1, | |
Moves.RIGHT: 1, | |
Moves.FORWARD: 1, | |
Moves.BACK: 1, | |
Moves.JUMP: 3 | |
}; | |
// collections can be used as streams | |
// stream is an object which emits other objects | |
// so we can process each one at a time | |
// dance is a collection so it can emit its members | |
dance | |
//map the move to its cost | |
.map( | |
(move) => moveCost[move] | |
) | |
//and for each cost print the result | |
.forEach( | |
(expense) => print('Cost of the move $expense') | |
); | |
} | |
enum Moves { | |
FORWARD, | |
BACK, | |
LEFT, | |
RIGHT, | |
JUMP, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment