-
Notifications
You must be signed in to change notification settings - Fork 0
/
coll.py
31 lines (25 loc) · 898 Bytes
/
coll.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class At:
def __rmatmul__(self, other): return self.rhs(other, self)
def __matmul__(self, other): return self.lhs(self, other)
def lhs(self, lhs, rhs): return self.rhs(lhs, rhs)
def rhs(self, lhs, rhs): return self.lhs(lhs, rhs)
class AsList(list, At):
def __call__(self, *args):
return AsList(*args)
def lhs(self, lhs, rhs):
return AsList(AsList(lhs)+AsList(rhs))
aslist = AsList()
class Chain(list, At):
def __call__(self, *args):
return self@args
def __getitem__(self, *args):
return self@(args,)
def lhs(self, lhs, rhs):
return Chain(((lhs,) if lhs else () + ((rhs,) if rhs else ()))
def __iter__(self):
for i in range(len(self)):
yield from super().__getitem__(i)
def __repr__(self):
return 'chain'+super().__repr__()
chain = Chain()
from itertools import chain as iterchain