3 ms·
>Also, it would be nice to have a pipe operator `%>%` such that You can absolutely define a pipe operator to apply functions. Something like class Pipeabl
by joshuamorton 8y ago
>Also, it would be nice to have a pipe operator `%>%` such that
You can absolutely define a pipe operator to apply functions. Something like
class Pipeable(object):
def __init__(self, f: Callable):
self.f = f
def __or__(self, other: Callable):
return Pipeable(other(self.f))
Then use it like
composed = Pipeable(foo) | f
Replace `|` with `>>` if you feel that conveys what you want better. Libraries already exist which provide this interface.
>Is that anti-Pythonic?
In a sense, yes. Operators and methods are defined in terms of objects, not in terms of abstract types.