Last active
March 16, 2018 22:47
-
-
Save f3ath/7539d1c6dc22e949b539f0bf56731485 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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