-
Notifications
You must be signed in to change notification settings - Fork 263
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 new side_effects
function
#122
Conversation
Whoops. I pushed this to the |
Interstingly this might be related to the In that case we want to cause some side effect whenever a function is called. I wonder if we should have a |
I've moved this to the |
My abbreviated two cents: this is short enough, simple enough, and may have more applications than I can currently think of, so go ahead and add it. To graduate from I think we may come up with a different (not necessarily better) function if we try to come up with additional examples. I saw when this PR was created and you asked for feedback, but, well, I haven't had much feedback to give. The function is simple enough, but it also feels related to "tee", "dup", monads, etc., which makes me wonder if there are other, more general ways to go about this. By the way, it looks like you didn't remove Regarding tracing of functions, yes, I still want to develop a way to easily perform tracing using a user-provided function. We can continue that discussion elsewhere, and I think a similar |
Thanks for the feedback. I agree that there is probably a better more general way to go about this. It feels like it's close to something very useful. I think it's a good candidate for the sandbox. Hopefully with use it will become clear what that very useful thing is. |
it is now in sandbox
Add new `side_effects` function
Merged into sandbox |
Interestingly, def tap(x):
print(x)
return x It also has I don't this we should copy these, but it does show that somebody else found them appropriate to add to a library (but just because it's in a library doesn't mean it's useful). A more general function may be more similar to def foo(*funcs):
def inner(*args, **kwargs):
return tuple(f(*args, **kwargs) for f in funcs)
return inner
def identity(x): return x
def double(x): return 2*x
def triple(x): return 3*x Thus: >>> combo = foo(identity, double, triple)
>>> combo(1)
(1, 2, 3)
>>> first(combo(1))
1 It's more involved, but it follows the tradition of composing functions instead of applying hidden functions to iterables. Just a thought. |
I think putting something to support debugging into def tap(func, x):
func(x)
return x I think that what you're proposing in def funcmap(funcs, arg):
result = []
for func in funcs:
result.append(func(arg))
return result This is similar to Or the following def funcmap(funcs, arg):
return map(lambda f: f(arg), funcs) |
Oh, I like this
where |
I might rename |
Large scale feedback on this would be appreciated. I suspect that there is probably a better way to accomplish this.
In general the goal is to provide a mechanism to support side effects. I suspect this is the watered down version of the core idea behind monads.
Mostly I suspect this to be used with debugging, e.g.