Skip to content

Instantly share code, notes, and snippets.

@GoodManWEN
Last active January 13, 2021 01:39
Show Gist options
  • Save GoodManWEN/351fe48e24d61b8a62adef3e4460259e to your computer and use it in GitHub Desktop.
Save GoodManWEN/351fe48e24d61b8a62adef3e4460259e to your computer and use it in GitHub Desktop.
pipe_draft
from functools import partial
from typing import Callable
__all__ = (
'PIPE',
'END'
)
class _pipe_end:
...
class _pipe_start:
def __init__(self):
self._storage = None
def __or__(self , other):
if isinstance(other , _pipe_end):
ret = self._storage
self._storage = None
return ret
elif isinstance(other , tuple):
self._storage = partial(*other)(self._storage)
elif isinstance(other , Callable):
self._storage = other(self._storage)
else:
self._storage = other
return self
PIPE = _pipe_start()
END = _pipe_end()
if __name__ == '__main__':
test = PIPE | range(10) | (map , lambda x:x + 1) | list | set | END
print(test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment