Programming in Dart: Functions & Closures

Jun 21 2022 · Dart 2.16, Flutter, DartPad

Part 2: Learn Anonymous Functions & Closures

17. Challenge: Write a Generic Function

Episode complete

Play next episode

About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 16. Learn Generic Functions Next episode: 18. Conclusion

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've reached locked video content where the transcript will be shown as obfuscated text.

Now it’s time for the last and final challenge of this course. You just watched two episodes on generics. Now it’s time to put your knowledge to the test.

var scores = [
    [96, 46, 87],
    [87, 78, 80],
    [90, 86, 95],

var interests = [
    ['Video Games', 'Reading', 'Soccer'],
    ['Gymnastics', 'Step Dancing', 'Softball'],
    ['Horseback Riding', 'Hockey', 'Writing']
List<T> flattenList
List<T> flattenList<T>
List<T> flattenList<T>(List<List<T>> list) {

var flatList = <T>[];
for (var item in list) {
    for (var subItem in item) {

return flatList;
// Takes in a list of lists and extracts all items into a single list
var flatScores = flattenList(scores);
var flatInterests = flattenList(interests);