-
Notifications
You must be signed in to change notification settings - Fork 117
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 _.withDefault combinator #166
Comments
Hi @joshuacc, Take a look a |
Ahhh! Wait, I see that your proposal works on the return. Maybe we could talk about how this operates with or augments |
@fogus I saw that, but if I'm reading right it operates on the opposite end of things. My understanding is that What I'm looking for in |
Right. I saw that right after hitting send. :( |
Hehe. Replying at the same time. 😁 One common use case that I could see for var arr = [
{ prop: "val" },
{ prop: "val" },
{}
];
_.map(arr, function (val) { return val; });
// => ["val", "val", undefined]
_.map(arr, _.withDefault(function (val) { return val; }, "default"));
// => ["val", "val", "default"] I think this fits as a nice complement to |
I like this idea a lot. The names |
Maybe fnull could get an alias like withDefaultArgs? |
The
_.withDefault
function would accept a function as its argument, and returns a new function that transparently replacesnull
/undefined
return values with a default value.Example:
May need a better name for the function, though.
The text was updated successfully, but these errors were encountered: