-
Notifications
You must be signed in to change notification settings - Fork 226
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
FirstOrDefault #20
Comments
Yep, its current implementation is broken. It doesn't expect that instead of a predicate, a default value can be passed as the first argument: Enumerable.prototype.firstOrDefault = function (predicate, defaultValue) {
if (defaultValue === undefined) defaultValue = null;
if (predicate != null) return this.where(predicate).firstOrDefault(null, defaultValue);
... I would fix it that way: Enumerable.prototype.firstOrDefault = function (predicate, defaultValue) {
if (predicate) {
if (typeof predicate === Types.Function)
return this.where(predicate).firstOrDefault(null, defaultValue);
defaultValue = predicate;
}
defaultValue = defaultValue || null;
... |
I like the change. Sorry I was an idiot and using the function incorrectly. I'm too used to javascript libraries doing the heavy lifting of checking input and adapting. C# isn't nearly as adaptable and this library is emulating C# |
Don't blame yourself, the authors of linq.js changed the signature at some moment and introduced this breaking change. See http://neue.cc/reference.htm, here your code sample works as expected. |
FirstOrDefault doesn't appear to work.
Enumerable.from([]).firstOrDefault(15) // null
The text was updated successfully, but these errors were encountered: