Last active
August 29, 2015 14:19
-
-
Save zoechi/dd4b8153518469e2f68a to your computer and use it in GitHub Desktop.
set.contains with custom equals
This file contains hidden or 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
// 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