-
Notifications
You must be signed in to change notification settings - Fork 75
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
Could set
accept a function?
#49
Comments
Maybe set(markdown, "html") or set({property: "html", function: markdown}) – these should be backwards compatible. |
I'll be happy to code it if you give the green light @tjmehta. |
IMO overloading this function makes it harder to understand and less elegant. It's easy to get carried away with overloading functions with functional behavior, var markdown = require("marked");
[{string: "..."}, {string: "..."}].map(function (obj) {
obj.html = markdown(obj.string)
return obj;
}); What do you think? |
Well yeah, that's what I did in the end. Or rather, loving the immutability of ... .map(function (obj) {
return set(obj, "html", markdown(obj.string));
}); I've just had the impression that |
But I must admit it seems less elegant, the way I proposed. How about making it an optional set({through: markdown, keypaths: false}, "html") |
I definitely like the idea. I even considered just assuming a a function as a value in set is a transform function. What about a separate method all-together, like setMap or something? |
Well, as you wish :) I guess I'd like the |
Yeah, I am not a fan of options objects, unless it's a last resort for a powerful function. I think rigidity of arguments leads to less usage confusion, and a simpler implementation. |
I'll do it just as you wish :) Now for the name, I'd go for something more generic. Because What do you think? |
How about key-map or keypath-map? [....].map(keypathMap({ |
I've just had another idea for that – in reference to #53. [{string: "..."}, {string: "..."}].map(compose
( set("html")
, [ noop
, compose(markdown, pluck("string"))
]
)); That would pipe every item through (item) =>
set("html")(item, pluck("string")(item))
Maybe we could avoid stuffing another function to 101 and an options object altogether. |
I like the idea of |
Well then @tjmehta , now #53 is almost ready – do we want this?
If so, we need to decide if we change Changing |
After thinking through keyMap I think it is a bit convoluted. I really like the literal form here var markdown = require("marked");
[{string: "..."}, {string: "..."}].map(function (obj) {
obj.html = markdown(obj.string)
return obj;
}); Versus [{string: "..."}, {string: "..."}].map(compose
( set("html")
, [ noop
, compose(markdown, pluck("string"))
]
)); I think the latter is much harder to read. |
I think so too. |
I would prefer |
Is it possible to bend
set
to set properties through a function? I mean like:The text was updated successfully, but these errors were encountered: