Skip to content

Instantly share code, notes, and snippets.

@amacdougall
Created August 2, 2016 19:10
Show Gist options
  • Select an option

  • Save amacdougall/de81ddbf777f1375854da97725d0a9eb to your computer and use it in GitHub Desktop.

Select an option

Save amacdougall/de81ddbf777f1375854da97725d0a9eb to your computer and use it in GitHub Desktop.
Very basic set-like collection, supporting only contains/add/remove.
function is(a) {
return b => a === b;
}
function isNot(a) {
return b => a !== b;
}
class SimpleMembershipSet {
constructor(values = null) {
this.values = values || [];
}
contains(v) {
return this.values.find(is(v));
}
add(v) {
if (!this.values.find(is(v))) {
this.values.push(v);
}
}
remove(v) {
this.values = this.values.filter(isNot(v));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment