-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Documentation - not clear that arrays are allowed in the first argument of applySpec #2396
Comments
This is not an answer to your question, but this is how I would express your algorithm in code: // T :: a -> (a -> b) -> b
const T = x => f => f(x);
R.map(T(5), [R.add(1), R.add(-1)]); // => [6, 4] The T combinator was added in #2309 and will be available—as |
@davidchambers Thanks for your comment. In my case, This is how I'm actually using it: // DOMNode -> [DOMNode]
const allDescendants =
node => compose(flatten, map(applySpec([identity, allDescendants])), allChildNodes)(node);
// doing this instead of filtering allDescendants in order to avoid potentially
// building a huge array and filtering it
// (String, String) -> DOMNode -> [DOMNode]
const descendants =
(localName, uri) => node => compose(
flatten,
applySpec([filter(hasName(localName, uri)), map(descendants(localName, uri))]),
allChildNodes
)(node); I'm very new to functional programming, so maybe there's a better way to go about this, but it produces the desired output. |
A PR to update the the documentation would be apt. This works only by accident of the implementation, but it's behavior worth keeping if we ever change the function. So a new test case would be a good idea too. |
@CrossEye Sure, I'll prepare a PR with some documentation adds and unit tests. Thanks. |
I spent about an hour and a half looking for a method that could take an array of functions, apply them to an arbitrary value, and produce an array of the results.
After some experimentation, I found out that
applySpec
is able to do precisely that:and that it even works on arrays within objects and objects within arrays, ad infinitum. But the documentation doesn't say anything about this.
I think it would be helpful if the docs mentioned that
applySpec
is able to do this, or is this deliberately undocumented?The text was updated successfully, but these errors were encountered: