Created
March 10, 2024 17:20
-
-
Save fredgrott/c0608092bed0583f8db099817f71cdee to your computer and use it in GitHub Desktop.
dart oop behavioral, iterator
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
// Copyright 2024 Fredrick Allan Grott. All rights reserved. | |
// Use of this source code is governed by a BSD-style | |
// license that can be found in the LICENSE file. | |
import 'package:iterator/rainbow_iterator.dart'; | |
void main() { | |
var rainbowColors = RainbowIterator(); | |
while (rainbowColors.moveNext()) { | |
print(rainbowColors.current); | |
} | |
/* | |
Red | |
Orange | |
Yellow | |
Green | |
Blue | |
Indigo | |
Violet | |
*/ | |
} |
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
// Copyright 2024 Fredrick Allan Grott. All rights reserved. | |
// Use of this source code is governed by a BSD-style | |
// license that can be found in the LICENSE file. | |
class RainbowIterator implements Iterator { | |
final _colors = ["Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet"]; | |
var _index = 0; | |
@override | |
String get current => _colors[_index++]; | |
@override | |
bool moveNext() => _index < _colors.length; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment