-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for the contains() function, fixes #88 #93
Conversation
return Return(false) | ||
} | ||
var h = l.head() | ||
return h === val ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we should add some helper function so we can use .equals()
powers of our structures. It'll also work with other 3rd party stuff that implements Setoid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point! I wasn't aware of this Setoid initiative. Nice to see that. So, we would have something like...
if (a.equals && b.equals) {
return a.equals(b);
}
return a === b;
?
not sure how it'll work for immutablejs if they don't implement Setoid though :( Maybe a user would have to add equals
to their prototypes? Didn't check how their collections are implemented. Also, I guess that won't work with JS arrays out of the box?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Immutable
has quite sophisticated implementation of is
-> https://github.com/facebook/immutable-js/blob/master/src/is.js
but I think we don't need that much, I think that sth like this would be enough:
if (a === b || (a !== a && b !== b)) {
return true;
}
if (!a || !b) {
return false;
}
if (isFunction(a.equals) && isFunction(b.equals)) {
return a.equals(b);
}
return false;
The a !== a && b !== b
is about NaN
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm you surely have thought about this more than I did, but the if (!a || !b)
frightens me. It makes it that "" != ""
, because !""
is true
. Maybe we should just do === undefined
or what it is you have in mind there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look that if we have a = ""
and b = ""
it'll be returned with true
from first condition.
This line is an optimisation to avoid function
checks.
If you don't like it it can be dropped, but it's not that evil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok i understand now. let's add this, i'll just add comments. too bad we don't (afaict) don't cover arrays though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one can always use our or immutable's is()
:
arr.some(a => is(a, b))
Or we can make it curried so:
arr.some(is(a))
;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure how it'll work for immutablejs if they don't implement Setoid though :( Maybe a user would have to add equals to their prototypes?
I missed this part somehow. All ImmutableJS
structures implement Setoid ;)
@@ -627,6 +649,9 @@ | |||
return fn(a) ? self : None() | |||
}) | |||
}, | |||
contains: function (val) { | |||
return this.isSome() ? this.val === val : false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...and use this helper to all equality checks.
done. I didn't squash the commits. Maybe it could make sense to export 'areEqual' to users of the library, not sure... |
Please run npm run publ
and commit changed dist/
:)
sorry :S when this is merged i'll rebase the forEach pull request and run publ there too |
No description provided.