Skip to content

Instantly share code, notes, and snippets.

@f3ath
Last active March 16, 2018 22:47
Show Gist options
  • Save f3ath/7539d1c6dc22e949b539f0bf56731485 to your computer and use it in GitHub Desktop.
Save f3ath/7539d1c6dc22e949b539f0bf56731485 to your computer and use it in GitHub Desktop.
class IMappable {
}
class MyList<P extends IMappable> {
final List<P> _list;
MyList.fromJson(Map<String, dynamic> json, P func(v))
: _list = new List<P>.from(json.values.map(func));
P operator[] (int index) {
return _list[index];
}
}
class Foo implements IMappable {
final val;
Foo(this.val);
}
final MyList<Foo> myList = new MyList<Foo>.fromJson({'a': 'aaa', 'b': 'bbb'}, (v) => new Foo(v));
void main() {
print(myList[0]);
print(myList[1]);
print(myList[0].val);
print(myList[1].val);
}
Instance of 'Foo'
Instance of 'Foo'
aaa
bbb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment