Programming in Dart: Functions & Closures

Jun 21 2022 · Dart 2.16, Flutter, DartPad

Part 2: Learn Anonymous Functions & Closures

11. Use Anonymous Functions

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 10. Introduction Next episode: 12. Map & Filter Collections

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

There are times when you need to provide a function, but you may not need to use that function in other areas of your code. In such a case, you can provide an anonymous function instead.

int modifyScores(List<int> scores, int Function(int, int) processor) {
  var total = 0;
  for (var score in scores) {
    total += processor(score, 2);    
  }
  return total;  
}
var scores = [56, 85, 34];
var total = modifyScores(scores,
(int a, int b) {

});
return a * b;
print(total);
var total = modifyScores(scores, (int a, int b) => a * b );