Created
May 6, 2019 21:38
-
-
Save cararemixed/23f3e22727829b0d6714467364ecc0e7 to your computer and use it in GitHub Desktop.
For @d_run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I picked
do
because it's short but other names likeinto
orpipe
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.