Skip to content

Instantly share code, notes, and snippets.

@swavkulinski
Created May 11, 2020 13:39
Show Gist options
  • Save swavkulinski/d2e2ff0116fb35d7458a112d963326ae to your computer and use it in GitHub Desktop.
Save swavkulinski/d2e2ff0116fb35d7458a112d963326ae to your computer and use it in GitHub Desktop.
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