Skip to content

Instantly share code, notes, and snippets.

@andrewackerman
Created June 14, 2019 21:39
Show Gist options
  • Save andrewackerman/db03cb725b9f25c38d4c453fc47d53f9 to your computer and use it in GitHub Desktop.
Save andrewackerman/db03cb725b9f25c38d4c453fc47d53f9 to your computer and use it in GitHub Desktop.
typedef T2 Foo2<T1, T2>(T1);
typedef T3 Foo3<T1, T2, T3>(T1, T2);
class Bar<A> {
final List<A> outer;
Bar(this.outer);
void run<B, C, D>(
List<B> inner,
Foo2<A, C> outerSelector,
Foo2<B, C> innerSelector,
Foo3<A, B, D> resultSelector,
) {
// This should print:
// [Person, Pet, String, Map<String, String>]
print([A, B, C, D]);
// This should print:
// List<Person>, List<Pet>, (Person) => String, (Pet) => String, (Person, Pet) => Map<String, String>
print([outer.runtimeType, inner.runtimeType, outerSelector.runtimeType, innerSelector.runtimeType, resultSelector.runtimeType]);
}
}
class Person {
final String name;
Person(this.name);
}
class Pet {
final String name;
final String owner;
Pet(this.name, this.owner);
}
main() {
final people = [
Person('Travis'),
Person('Terry'),
Person('Charlotte'),
Person('Benny'),
];
final pets = [
Pet('Barley', 'Terry'),
Pet('Boots', 'Terry'),
Pet('Whiskers', 'Charlotte'),
Pet('Daisy', 'Benny'),
];
Bar(people).run(
pets,
(person) => person.name,
(pet) => pet.name,
(person, pet) => { 'person': person.name, 'pet': pet.name },
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment