-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelementwise.py
More file actions
3271 lines (2506 loc) · 90 KB
/
elementwise.py
File metadata and controls
3271 lines (2506 loc) · 90 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
Elementwise - Lazy operation proxies for iterables
==================================================
Elementwise provides convenient, fully lazy, abstract programming behavior for
interacting with iterable objects. All attempts at attribute access on
OperationProxy objects return generator factories wrapped in OperationProxy
objects. This means that you can generatively build up complex operation chains
and apply these chains of operations repeatedly, to different source iterables.
Additionally, each OperationProxy object has a reference to its parent
OperationProxy, allowing you to traverse up the function tree, undoing
operations or modying previous processes.
Elementwise provides three proxy objects:
1.) :class:`ElementwiseProxy`
This broadcasts all operations performed on the proxy to every member of the
proxied iterable.
2.) :class:`PairwiseProxy`
This treats the arguments of all operations performed as iterables which
emit the correct argument value for the operation on the element from the
proxied iterable with the same index. For example::
>>> PairwiseProxy([1, 2, 3, 4]) + [1, 2, 3, 4]
PairwiseProxy([2, 4, 6, 8])
3.) :class:`RecursiveElementwiseProxy`
This behaves like :class:`ElementwiseProxy`, with the notable exception that
when a member value is a non string iterable, it will recursively try to
apply the operation to child nodes. This proxy is capable of arbitrary
graph traversal in a depth first fashion, and will not visit a node twice.
Each of the proxy objects can mutate into any of the other types by calling a
mutator method.
* :meth:`ElementwiseProxyMixin.each`
mutates the current proxy into an :class:`ElementwiseProxy`.
* :meth:`PairwiseProxyMixin.pair`
mutates the current proxy into a :class:`PairwiseProxy`.
* :meth:`RecursiveElementwiseProxyMixin.recurse`
mutates the current proxy into a :class:`RecursiveElementwiseProxy`.
When you would like to perform the operation chain represented by your proxy,
simply iterate over it. The easiest way to do this is probably to call list with
the proxy as the argument.
If you would like to perform the same operation chain on another iterable,
all :class:`OperationProxy` subclasses support :meth:`OperationProxy.replicate`
which takes an iterable and generates a new chain, which is a duplicate of the
current chain with that iterable as the base data source.
If for some reason you would like to undo an operation, all :class:`OperationProxy`
subclasses support :meth:`OperationProxy.undo`, which accepts an integer number
of operations that should be undone (defaulting to 1) and returns a reference to
the :class:`OperationProxy` representing that step in the chain.
.. note::
There are some exceptions to the broadcasting behavior that can not be
circumvented. This includes most methods uesd by builtin types that were
formerly functions, such as __str__ and __nonzero__. When you need to
broadcast these operations, use :meth:`ElementwiseProxy.apply`.
"""
from decorator import decorator
import collections
import itertools
import operator
import types
__author__ = 'Nathan Rice <nathan.alexander.rice@gmail.com>'
# We don't want to evaluate this until absolutely required.
_iterable = lambda x: object.__getattribute__(x, "iterable")
def _cacheable(proxy):
try:
return object.__getattribute__(proxy, "__cacheable__")
except AttributeError:
return False
def create_cell(obj):
"""Create a cell object which references `obj`."""
return (lambda: obj).func_closure[0]
def copy_func(f, code=None, globals_=None, name=None, argdefs=None, closure=None):
"""Create a copy of a function, replacing any portions specified."""
return types.FunctionType(
code or f.func_code,
globals_ or f.func_globals,
name or f.func_name,
argdefs or f.func_defaults,
closure or f.func_closure
)
def as_strlike(iterable, f=str):
"""
Generate a string-like representation of `iterable`, using `f`. repr
requires special case behavior, since the repr() of a string is enclosed in
an additional set of quotes.
"""
if f == repr: # don't repr() strings...
f = lambda x: isinstance(x, basestring) and str(x) or repr(x)
visited = set()
def stringify_iterable(iterable):
if not isinstance(iterable, (collections.Iterable)) or \
isinstance(iterable, basestring):
yield f(iterable)
elif id(iterable) not in visited:
visited.add(id(iterable))
yield f("(")
first = True
for i in iterable:
if not first:
yield f(", ")
else:
first = False
for j in stringify_iterable(i):
yield j
yield f(")")
return f("").join(stringify_iterable(iterable))
def graphmap(f, graph):
"""
Depth first graph traversal and function application. Cycles are
avoided by maintaining a set of observed object ids and testing for set
membership before edge traversal.
"""
visited = set()
def traverse_branch(branch):
for node in branch:
if id(node) in visited:
continue
if isinstance(node, (collections.Iterable)) and \
not isinstance(node, basestring):
# We are at a branch
visited.add(id(node))
yield traverse_branch(node)
else:
# We are at a leaf
yield f(node)
for n in traverse_branch(graph):
yield n
class IteratorProxy(object):
"""
This is a simple proxy object for iterators, which provides a few extra
features:
* Supports value caching.
* Accepts callables that generates iterables.
* Supports slicing, and will try to behave intelligently about how it does so, depending on whether the source iterable is a sequence.
* Concatenates iterators using the + operator.
* Generates a cartesian product of two iterators using the \* operator.
* Generates a cartesian product of an iterable multiplied by itself N times using the (\* N) expression.
"""
def __init__(self, iterable, cacheable=False):
self._cache = []
self.cacheable = cacheable
self.iterable = iterable
def __iter__(self):
"""
If the underlying iterable is cacheable and the cache has been built up,
the cache will be iterated over. Otherwise the underlying iterable will
be iterated over.
"""
if not self.cache:
if isinstance(self.iterable, types.FunctionType):
iterable = self.iterable()
else:
iterable = self.iterable
for item in iterable:
yield item
self.cache.append(item)
else:
if isinstance(self.cache, types.FunctionType):
iterable = self.cache()
else:
iterable = self.cache
for item in iterable:
yield item
@property
def cache(self):
"""
The cache property returns cached values, or redirects to the iterable
property if the source iterable is not cacheable.
"""
if not self.cacheable:
return self.iterable
else:
return self._cache
def __getitem__(self, key):
"""
Respect the getitem attribute on the parent if it exists. Otherwise,
try to use itertools.islice.
"""
iterable_getitem = getattr(self.iterable, "__getitem__", None)
if iterable_getitem:
return iterable_getitem(key)
elif isinstance(key, types.SliceType):
return itertools.islice(self, key.start, key.stop, key.step)
else:
return itertools.islice(self, key, key + 1)
def __add__(self, other):
"""
Concatenates self and other. Implemented using itertools.chain.
"""
return itertools.chain(self, other)
def __mul__(self, other):
"""
If other is an integer, return the cartesian product of self repeated
`other` times. Otherwise, return the cartiasn product of `self` and
`other`
"""
if isinstance(other, int):
return itertools.product(self, repeat=other)
else:
return itertools.product(self, other)
@decorator
def chainable(f, self, *args, **kwargs):
"""
Chainable functions should return an instance of their class, with a
reference to their parent function.
:param f:
The function to be decorated.
:type f:
FunctionType
:param self:
The chainable instance.
:type self:
:class:`OperationProxy` subclass
"""
return type(self)(f(self, *args, **kwargs), self)
@decorator
def cacheable(f, self, *args, **kwargs):
"""
:param f:
The function to be decorated.
:type f:
FunctionType
:param self:
The cacheable instance.
:type self:
:class:`OperationProxy` subclass
Cacheable functions have their return iterable wrapped in an
IterableProxy. If `self`.__cacheable__ evaluates to True, the
IterableProxy will cache results as it is iterated over.
"""
iteratable = f(self, *args, **kwargs)
return IteratorProxy(iteratable, _cacheable(self))
class ProxyMixin(object):
"""Base class for Proxy Mixins."""
class ElementwiseProxyMixin(ProxyMixin):
"""
Provides iterable objects with a proxy that broadcasts operations to member
elements.
"""
@property
def each(self):
"""Syntactic sugar for ElementwiseProxy(self)"""
parent = isinstance(self, OperationProxy) and self or None
return ElementwiseProxy(self, parent)
class RecursiveElementwiseProxyMixin(ProxyMixin):
"""
Provides iterable objects with a proxy that broadcasts operations
recursively to member elements.
"""
@property
def recurse(self):
"""Syntactic sugar for RecursiveElementwiseProxy(self)"""
parent = isinstance(self, OperationProxy) and self or None
return RecursiveElementwiseProxy(self, parent)
class PairwiseProxyMixin(ProxyMixin):
"""
Provides iterable objects with a proxy that performs pairwise operations
using elements of supplied iterables.
"""
@property
def pair(self):
"""Syntactic sugar for PairwiseProxy(self)"""
parent = isinstance(self, OperationProxy) and self or None
return RecursiveElementwiseProxy(self, parent)
class OperationProxy(object):
"""
Base class for Proxy objects.
"""
def __init__(self, iterable=tuple(), parent=None):
self.iterable = iterable
self.parent = parent
def replicate(self, iterable):
"""
Creates a copy of this operation chain, with `iterable` as the source.
"""
def ancestors():
current = self
while current is not None:
yield current
current = object.__getattribute__(current, "parent")
ancestor_list = list(ancestors())
parent = type(ancestor_list[-1])(iterable)
for ancestor in reversed(ancestor_list[:-1]):
# Every ancester after the first will have an IteratorProxy that
# wraps a function.
iterable = object.__getattribute__(ancestor, "iterable").iterable
# The only thing we need to do is get the "self" name in the closure
# to point to the new OperationProxy.
new_closure = (create_cell(parent),) + iterable.func_closure[1:]
new_iterable = copy_func(iterable, closure=new_closure)
iterator_proxy = IteratorProxy(new_iterable, _cacheable(self))
# Here we build up the chain.
new_ancestor = type(ancestor)(iterator_proxy, parent)
parent = new_ancestor
# Now return parent, which is a copy of this, with references to copies
# of all chain members.
return parent
def undo(self, steps=1):
"""
Starting from the current operation, undo the previous `steps`
operations in the chain.
:parameter steps:
The number of operations to undo.
:type steps:
int
:returns:
A new chain reprenseting the state of the chain `steps` operations
prior.
:rtype:
`OperationProxy` (or a subclass thereof)
"""
current = self
for step in range(steps):
parent = object.__getattribute__(current, "parent")
if parent:
current = parent
else:
break
return current
def __getattr__(self, item):
iterable = IteratorProxy(_iterable(self), _cacheable(self))
return type(self)((e.__getattribute__(item) for e in iterable), self)
def __iter__(self):
return iter(_iterable(self))
def __nonzero__(self):
return bool(_iterable(self))
def __str__(self):
return ", ".join(str(e) for e in _iterable(self))
def __repr__(self):
return "%s([%s])" % (type(self).__name__ , ", ".join(repr(e) for e in _iterable(self)))
def __unicode__(self):
return u", ".join(unicode(e) for e in _iterable(self))
@chainable
def __reversed__(self):
return lambda: reversed(_iterable(self))
@chainable
def __getitem__(self, item):
# Get the original iterable.
current = self
while current.parent:
current = current.parent
# Now try to replicate this iterable with the parent
return self.replicate(current[item])
@chainable
@cacheable
def __hash__(self):
return lambda: (hash(e) for e in _iterable(self))
@chainable
@cacheable
def __invert__(self):
return lambda: (~e for e in _iterable(self))
@chainable
@cacheable
def __index__(self):
return lambda: (operator.index(e) for e in _iterable(self))
@chainable
@cacheable
def __neg__(self):
return lambda: (-e for e in _iterable(self))
@chainable
@cacheable
def __pos__(self):
return lambda: (+e for e in _iterable(self))
@chainable
@cacheable
def __abs__(self):
return lambda: (e.__abs__() for e in _iterable(self))
class ElementwiseProxy(OperationProxy, PairwiseProxyMixin,
RecursiveElementwiseProxyMixin):
"""
Provides elementwise operator behavior, attribute access and method calls
over a parent iterable.
.. testsetup::
nums = ElementwiseProxy([1, 2, 3, 4])
First, create an ElementwiseProxy from any iterable, like so::
nums = ElementwiseProxy([1, 2, 3, 4])
You can perform a large vareity of operations on the proxy, and it will
create a chain of operations to be applied to the contents of the iterable
being proxied. The proxy is fully lazy, so none of the operations will be
applied until you begin to request values from the proxy by iterating over
it.
For example:
>>> print nums.bit_length()
1, 2, 2, 3
>>> nums + 1
2, 3, 4, 5
>>> print nums * 2
2, 4, 6, 8
>>> print nums == 2
False, True, False, False
>>> print ((nums + 1) * 2 + 3).apply(float)
7.0, 9.0, 11.0, 13.0
>>> print (nums.apply(float) + 0.0001).apply(round, 2)
1.0, 2.0, 3.0, 4.0
>>> print abs(nums - 3)
2, 1, 0, 1
>>> print (nums * 2 + 3) / 4
>>> list(efoo2.undo(3))
1, 2, 3, 4
>>> print ((nums * 2 + 3) / 4).replicate([2, 2, 3, 3])
1, 1, 2, 2
>>> words = ElementwiseProxy(["one", "two", "three", "four"])
>>> print (words + " little indians").upper().split(" ").apply(reversed).apply("_".join) * 2
'INDIANS_LITTLE_ONEINDIANS_LITTLE_ONE', 'INDIANS_LITTLE_TWOINDIANS_LITTLE_TWO', 'INDIANS_LITTLE_THREEINDIANS_LITTLE_THREE', 'INDIANS_LITTLE_FOURINDIANS_LITTLE_FOUR'
"""
@chainable
@cacheable
def apply(self, func, *args, **kwargs):
"""
:parameter func:
The function to be applied.
:returns:
A function which returns::
(func(e, *args, **kwargs) for e in self)
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (func(e, *args, **kwargs) for e in _iterable(self))
@chainable
@cacheable
def __call__(self, *args, **kwargs):
"""
:returns:
A function which returns::
(e(*args, **kwargs) for e in self)
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (e(*args, **kwargs) for e in _iterable(self))
@chainable
@cacheable
def __add__(self, other):
"""
:returns:
A function which returns::
(e + other for e in self)
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (e + other for e in _iterable(self))
@chainable
@cacheable
def __sub__(self, other):
"""
:returns:
A function which returns::
(e - other for e in self).
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (e - other for e in _iterable(self))
@chainable
@cacheable
def __mul__(self, other):
"""
:returns:
A function which returns::
(e * other for e in self).
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (e * other for e in _iterable(self))
@chainable
@cacheable
def __floordiv__(self, other):
"""
:returns:
A function which returns::
(e // other for e in self).
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (e // other for e in _iterable(self))
@chainable
@cacheable
def __mod__(self, other):
"""
:returns:
A function which returns::
(e % other for e in self).
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (e % other for e in _iterable(self))
@chainable
@cacheable
def __divmod__(self, other):
"""
:returns:
A function which returns::
(divmod(e, other) for e in self).
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (divmod(e, other) for e in _iterable(self))
@chainable
@cacheable
def __pow__(self, other, modulo=None):
"""
:returns:
A function which returns::
(pow(e, other, modulo) for e in self).
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (pow(e, other, modulo) for e in _iterable(self))
@chainable
@cacheable
def __lshift__(self, other):
"""
:returns:
A function which returns::
(e << other for e in self).
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (e << other for e in _iterable(self))
@chainable
@cacheable
def __rshift__(self, other):
"""
:returns:
A function which returns::
(e >> other for e in self).
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (e >> other for e in _iterable(self))
@chainable
@cacheable
def __div__(self, other):
"""
:returns:
A function which returns::
(e / other for e in self).
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (e / other for e in _iterable(self))
@chainable
@cacheable
def __truediv__(self, other):
"""
:returns:
A function which returns::
(e / other for e in self), using truediv.
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (e.__truediv__(other) for e in _iterable(self))
@chainable
@cacheable
def __radd__(self, other):
"""
:returns:
A function which returns::
(other + e for e in self).
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (other + e for e in _iterable(self))
@chainable
@cacheable
def __rand__(self, other):
"""
:returns:
A function which returns::
(other & e for e in self).
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (other & e for e in _iterable(self))
@chainable
@cacheable
def __rdiv__(self, other):
"""
:returns:
A function which returns::
(other / e for e in self).
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (other / e for e in _iterable(self))
@chainable
@cacheable
def __rdivmod__(self, other):
"""
:returns:
A function which returns::
(divmod(other, e) for e in self).
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (divmod(other, e) for e in _iterable(self))
@chainable
@cacheable
def __rfloordiv__(self, other):
"""
:returns:
A function which returns::
(other // e for e in self).
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (other // e for e in _iterable(self))
@chainable
@cacheable
def __rlshift__(self, other):
"""
:returns:
A function which returns::
(other << e for e in self).
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (other << e for e in _iterable(self))
@chainable
@cacheable
def __rmod__(self, other):
"""
:returns:
A function which returns::
(e % other for e in self)
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (other % e for e in _iterable(self))
@chainable
@cacheable
def __rmul__(self, other):
"""
:returns:
A function which returns::
(other * e for e in self).
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (other * e for e in _iterable(self))
@chainable
@cacheable
def __ror__(self, other):
"""
:returns:
A function which returns::
(other | e for e in self).
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (other | e for e in _iterable(self))
@chainable
@cacheable
def __rpow__(self, other):
"""
:returns:
A function which returns::
(pow(other, e) for e in self)
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (pow(other, e) for e in _iterable(self))
@chainable
@cacheable
def __rrshift__(self, other):
"""
:returns:
A function which returns::
(other >> e for e in self)
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (other >> e for e in _iterable(self))
@chainable
@cacheable
def __rsub__(self, other):
"""
:returns:
A function which returns::
(other - e for e in self)
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (other - e for e in _iterable(self))
@chainable
@cacheable
def __rtruediv__(self, other):
"""
:returns:
A function which returns::
(other / e for e in self)
using truediv.
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (e.__rtruediv__(other) for e in _iterable(self))
@chainable
@cacheable
def __rxor__(self, other):
"""
:returns:
A function which returns::
(other ^ e for e in self)
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (other ^ e for e in _iterable(self))
@chainable
@cacheable
def __contains__(self, item):
"""
:returns:
A function which returns::
(item in e for e in self)
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (item in e for e in _iterable(self))
@chainable
@cacheable
def __eq__(self, other):
"""
:returns:
A function which returns::
(e == other for e in self)
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (e == other for e in _iterable(self))
@chainable
@cacheable
def __ne__(self, other):
"""
:returns:
A function which returns::
(e != other for e in self)
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (e != other for e in _iterable(self))
@chainable
@cacheable
def __le__(self, other):
"""
:returns:
A function which returns::
(e <= other for e in self)
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (e <= other for e in _iterable(self))
@chainable
@cacheable
def __lt__(self, other):
"""
:returns:
A function which returns::
(e < other for e in self)
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (e < other for e in _iterable(self))
@chainable
@cacheable
def __gt__(self, other):
"""
:returns:
A function which returns::
(e > other for e in self)
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (e > other for e in _iterable(self))
@chainable
@cacheable
def __ge__(self, other):
"""
:returns:
A function which returns::
(e >= other for e in self)
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (e >= other for e in _iterable(self))
@chainable
@cacheable
def __cmp__(self, other):
"""
:returns:
A function which returns::
(cmp(e, other) for e in self)
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (cmp(e, other) for e in _iterable(self))
@chainable
@cacheable
def __and__(self, other):
"""
:returns:
A function which returns::
(e & other for e in self)
:rtype:
FunctionType -> GeneratorType
"""
return lambda: (e & other for e in _iterable(self))