Created
November 2, 2019 05:48
-
-
Save AlexKenbo/b202a4b4313435b8cec92b16708681f9 to your computer and use it in GitHub Desktop.
Functional programming in dart
This file contains hidden or 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
String scream(int length) => "A${'a' * length}h!"; | |
main() { | |
final values = [1, 2, 3, 5, 10, 50]; | |
//Normal not functional: | |
print('Normal, not functional: '); | |
for (var length in values) { | |
print(scream(length)); | |
} | |
print('Functional: '); | |
values.map(scream).forEach(print); | |
print('Skipped 1 and then prints the next 3 values: '); | |
values.skip(1).take(3).map(scream).forEach(print); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment