Skip to content

Instantly share code, notes, and snippets.

@zoechi
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoechi/dd4b8153518469e2f68a to your computer and use it in GitHub Desktop.
Save zoechi/dd4b8153518469e2f68a to your computer and use it in GitHub Desktop.
set.contains with custom equals
// SO 29567322
class Action {
final Function function;
final String description;
Action(this.function, this.description);
call() => function();
int get hashCode => description.hashCode;
@override
bool operator== (other) {
if(other is! Action) {
return false;
}
return description == (other as Action).description;
}
@override
String toString() => description;
}
void main() {
Set<Action> actions = new Set()
..add(new Action(() => print("a"), "print a"))
..add(new Action(() => print("a"), "print a"))
..add(new Action(() => print("b"), "print b"));
print(actions);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment