Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
1
  • Loading branch information
tandav committed Nov 6, 2023
1 parent cfe0b72 commit 3ad84f7
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions pipe21.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,26 @@ def __init__(self, f=None, *args, **kw):
self.kw = kw


class Pipe (B): __ror__ = lambda self, x: self.f(x, *self.args, **self.kw)
class Map (B): __ror__ = lambda self, it: map(self.f, it)
class Filter (B): __ror__ = lambda self, it: filter(self.f, it)
class Pipe(B):
def __ror__(self, x):
return self.f(x, *self.args, **self.kw)


class Map (B): __ror__ = lambda self, it: (self.f(x) for x in it)
class Filter (B): __ror__ = lambda self, it: (x for x in it if self.f(x))
class Reduce (B): __ror__ = lambda self, it: functools.reduce(self.f, it, *self.args)
class MapKeys (B): __ror__ = lambda self, it: it | Map(lambda kv: (self.f(kv[0]), kv[1]))
class MapValues (B): __ror__ = lambda self, it: it | Map(lambda kv: (kv[0], self.f(kv[1])))
class MapKeys (B): __ror__ = lambda self, it: ((self.f(kv[0]), kv[1]) for kv in it)
class MapValues (B): __ror__ = lambda self, it: ((kv[0], self.f(kv[1])) for kv in it)
class FilterFalse (B): __ror__ = lambda self, it: itertools.filterfalse(self.f, it)
class FilterKeys (B): __ror__ = lambda self, it: it | Filter(lambda kv: kv[0] | Pipe(self.f or bool))
class FilterValues (B): __ror__ = lambda self, it: it | Filter(lambda kv: kv[1] | Pipe(self.f or bool))
class FlatMap (B): __ror__ = lambda self, it: it | Map(self.f) | Pipe(itertools.chain.from_iterable)
class FilterKeys (B): __ror__ = lambda self, it: (kv for kv in it if (self.f or bool)(kv[0]))
class FilterValues (B): __ror__ = lambda self, it: (kv for kv in it if (self.f or bool)(kv[1]))
class FlatMap (B): __ror__ = lambda self, it: itertools.chain.from_iterable(self.f(x) for x in it)
class FlatMapValues(B): __ror__ = lambda self, it: it | FlatMap(lambda kv: ((kv[0], x) for x in self.f(kv[1])))
class KeyBy (B): __ror__ = lambda self, it: it | Map(lambda x: (self.f(x), x))
class ValueBy (B): __ror__ = lambda self, it: it | Map(lambda x: (x, self.f(x)))
class Append (B): __ror__ = lambda self, it: it | Map(lambda x: (*x, self.f(x)))
class Keys (B): __ror__ = lambda self, it: it | Map(lambda kv: kv[0])
class Values (B): __ror__ = lambda self, it: it | Map(lambda kv: kv[1])
class KeyBy (B): __ror__ = lambda self, it: ((self.f(x), x) for x in it)
class ValueBy (B): __ror__ = lambda self, it: ((x, self.f(x)) for x in it)
class Append (B): __ror__ = lambda self, it: ((*x, self.f(x)) for x in it)
class Keys (B): __ror__ = lambda self, it: (kv[0] for kv in it)
class Values (B): __ror__ = lambda self, it: (kv[1] for kv in it)
class Grep (B): __ror__ = lambda self, it: it | MapSwitch([(lambda x: self.kw.setdefault('i', False), str.lower)]) | Filter(lambda x: re.search(self.f.lower() if self.kw['i'] else self.f, x))
class GrepV (B): __ror__ = lambda self, it: it | MapSwitch([(lambda x: self.kw.setdefault('i', False), str.lower)]) | FilterFalse(lambda x: re.search(self.f.lower() if self.kw['i'] else self.f, x))
class IterLines (B): __ror__ = lambda self, p: p | Pipe(open) | Pipe(lambda t: t | Map(str.strip) if self.kw.get('strip', True) else t)
Expand All @@ -37,15 +41,15 @@ class Slice (B): __ror__ = lambda self, it: itertools.islice(it, self.f,
class Take (B): __ror__ = lambda self, it: it | Slice(self.f) | Pipe(tuple)
class Chunked (B): __ror__ = lambda self, it: iter(functools.partial(lambda n, i: i | Take(n), self.f, iter(it)), ())
class Sorted (B): __ror__ = lambda self, it: sorted(it, **self.kw)
class GroupBy (B): __ror__ = lambda self, it: it | Sorted(key=self.f) | Pipe(itertools.groupby, key=self.f)
class GroupBy (B): __ror__ = lambda self, it: sorted(it, key=self.f) | Pipe(itertools.groupby, key=self.f)
class ReduceByKey (B): __ror__ = lambda self, it: it | GroupBy(lambda kv: kv[0]) | MapValues(lambda kv: kv | Values() | Reduce(self.f)) | Pipe(list)
class Apply (B): __ror__ = lambda self, x: x | Exec(self.f, x)
class StarPipe (B): __ror__ = lambda self, x: self.f(*x)
class StarMap (B): __ror__ = lambda self, x: itertools.starmap(self.f, x)
class StarFlatMap (B): __ror__ = lambda self, x: x | StarMap(self.f) | Pipe(itertools.chain.from_iterable)
class MapApply (B): __ror__ = lambda self, it: it | Map(lambda x: x | Apply(self.f))
class MapApply (B): __ror__ = lambda self, it: (x | Apply(self.f) for x in it)
class Switch (B): __ror__ = lambda self, x: self.f | FilterKeys(lambda p: p(x)) | Values() | Map(lambda f: f(x)) | Pipe(next, x)
class MapSwitch (B): __ror__ = lambda self, it: it | Map(lambda x: x | Switch(self.f))
class MapSwitch (B): __ror__ = lambda self, it: (x | Switch(self.f) for x in it)
class YieldIf (B): __ror__ = lambda self, it: ((self.f or (lambda y: y))(x) for x in it if self.kw.get('key', bool)(x))
class Join (B): __ror__ = lambda self, it: it | FlatMap(lambda x: ((x, y) for y in self.f if self.kw.get('key', operator.eq)(x, y)))

Expand All @@ -56,14 +60,14 @@ class DelItem (B): __ror__ = lambda self, x: x | Exec(operator.delitem, x
class GetAttr (B): __ror__ = lambda self, x: getattr(x, self.f)
class SetAttr (B): __ror__ = lambda self, x: x | Exec(setattr, x, self.f, self.args[0])
class DelAttr (B): __ror__ = lambda self, x: x | Exec(delattr, x, self.f)
class MapGetItem (B): __ror__ = lambda self, it: it | Map(lambda kv: kv | GetItem(self.f))
class MapSetItem (B): __ror__ = lambda self, it: it | Map(lambda kv: kv | SetItem(self.f, self.args[0]))
class MapDelItem (B): __ror__ = lambda self, it: it | Map(lambda kv: kv | DelItem(self.f))
class MapGetAttr (B): __ror__ = lambda self, it: it | Map(lambda kv: kv | GetAttr(self.f))
class MapSetAttr (B): __ror__ = lambda self, it: it | Map(lambda kv: kv | SetAttr(self.f, self.args[0]))
class MapDelAttr (B): __ror__ = lambda self, it: it | Map(lambda kv: kv | DelAttr(self.f))
class MapGetItem (B): __ror__ = lambda self, it: (kv | GetItem(self.f) for kv in it)
class MapSetItem (B): __ror__ = lambda self, it: (kv | SetItem(self.f, self.args[0]) for kv in it)
class MapDelItem (B): __ror__ = lambda self, it: (kv | DelItem(self.f) for kv in it)
class MapGetAttr (B): __ror__ = lambda self, it: (kv | GetAttr(self.f) for kv in it)
class MapSetAttr (B): __ror__ = lambda self, it: (kv | SetAttr(self.f, self.args[0]) for kv in it)
class MapDelAttr (B): __ror__ = lambda self, it: (kv | DelAttr(self.f) for kv in it)
class MethodCaller (B): __ror__ = lambda self, x: operator.methodcaller(self.f, *self.args, **self.kw)(x)
class MapMethodCaller(B): __ror__ = lambda self, it: it | Map(lambda x: x | MethodCaller(self.f, *self.args, **self.kw))
class MapMethodCaller(B): __ror__ = lambda self, it: (x | MethodCaller(self.f, *self.args, **self.kw) for x in it)


class Unique(B):
Expand Down

0 comments on commit 3ad84f7

Please sign in to comment.