Skip to content

Instantly share code, notes, and snippets.

@cararemixed
Created May 6, 2019 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cararemixed/23f3e22727829b0d6714467364ecc0e7 to your computer and use it in GitHub Desktop.
Save cararemixed/23f3e22727829b0d6714467364ecc0e7 to your computer and use it in GitHub Desktop.
For @d_run
class do(object):
def __init__(self, fn, *args, **kwargs):
self.fn = fn
self.args = args
self.kwargs = kwargs
def __rrshift__(self, other):
return self.fn(other, *self.args, **self.kwargs)
42 >> do(print)
@cararemixed
Copy link
Author

I picked do because it's short but other names like into or pipe might make sense. You could decorate the functions as well to negate the need for this form as well, but I don't know how much magic you actually want. I'm happy to extend it if you want to see an example of this in action.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment