Dart by Example: Functions

1. // A simple function definition
2. yell(str) => str.toUpperCase();

4. // Functions can have type annotations
5. List lines(String str) {
6. return str.split('\n');
7. }

9. main() {
10. var poemLines = lines(poem);
11. print(yell(poemLines.first));

13. // functions are first-class
14. var whisper = (String str) => str.toLowerCase();
15. print(poemLines.map(whisper).last);
16. }

18. const poem = '''
19. The wren
20. Earns his living
21. Noiselessly.''';
1. $ dart functions.dart
2. THE WREN
3. noiselessly.

by @jryanio | source | license