Skip to content
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

Feature idea: API for accessing adverb's underlying function(s) #1071

Closed
mmuurr opened this issue Apr 11, 2023 · 1 comment
Closed

Feature idea: API for accessing adverb's underlying function(s) #1071

mmuurr opened this issue Apr 11, 2023 · 1 comment

Comments

@mmuurr
Copy link

mmuurr commented Apr 11, 2023

At times I find it's useful to retain the original function when passed to an adverb, such as possibly().
Obviously, when the original function is available by direct reference, this is a non-issue:

orig_f <- function(...) { do_some_stuff };
new_f <- purrr::possibly(f)

so_something_with(orig_f)  ## still have access to orig_f

But when using adverbs in a slightly more functional (and less-declarative) manner, I find I like to do something like this:

the_only_f <- (function(...) { do_some_stuff }) |> purrr::possibly()

... and when wanting to do something with the original function I do (something along the lines of):

environment(the_only_f)$.f

That ^ approach is a bit of a leaky abstraction, so I'm wondering if there's appetite for an accessor like:

get_wrapped_fun(the_only_f)

The only {purrr} adverb where that example API wouldn't really work is compose(), though a more generic:

get_wrapped_funs(adverbed_f)

... could yield a list of functions.

Just a thought, as whenever I find myself plucking objects out of a function's environment I think to myself, "this is unsafe" :-)

Cheers!

@hadley
Copy link
Member

hadley commented Jul 26, 2023

Thanks for filing this issue! Unfortunately, while I think it's an interesting idea, I think it's out of scope for this package: developing good software requires relentless focus, which means that we have to say no to many good ideas. Even though I'm closing this issue, I really appreciate the feedback, and hope you'll continue to contribute in the future 😄

@hadley hadley closed this as completed Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants