Get immediate access to this and over 1,500+ other videos and books.

Boost your skills with a raywenderlich.com Beginner subscription. With over 60+ video courses and our core foundational programming books bundled in one subscription, it’s simply the best investment you can make in your development career.

Use Anonymous Functions

This video was last updated on Jun 21 2022

Learn the basics of writing anonymous functions as well as why you’d even want to use them in the first place.

Contributors

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a raywenderlich.com Professional subscription.

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 );

Reviews

Comments