MCPcopy Create free account
hub / github.com/EntilZha/PyFunctional / Sequence

Class Sequence

functional/pipeline.py:29–1775  ·  view source on GitHub ↗

Sequence is a wrapper around any type of sequence which provides access to common functional transformations and reductions in a data pipeline style

Source from the content-addressed store, hash-verified

27
28
29class Sequence(object):
30 """
31 Sequence is a wrapper around any type of sequence which provides access to common
32 functional transformations and reductions in a data pipeline style
33 """
34
35 def __init__(self, sequence, transform=None, engine=None, max_repr_items=None):
36 # pylint: disable=protected-access
37 """
38 Takes a Sequence, list, tuple. or iterable sequence and wraps it around a Sequence object.
39 If the sequence is already an instance of Sequence, it will in total be wrapped exactly
40 once. A TypeError is raised if sequence is none of these.
41
42 :param sequence: sequence of items to wrap in a Sequence
43 :param transform: transformation to apply
44 :param engine: execution engine
45 :param max_repr_items: maximum number of items to print with repr
46 :return: sequence wrapped in a Sequence
47 """
48 self.engine = engine or ExecutionEngine()
49 if isinstance(sequence, Sequence):
50 self._max_repr_items = max_repr_items or sequence._max_repr_items
51 self._base_sequence = sequence._base_sequence
52 self._lineage = Lineage(prior_lineage=sequence._lineage, engine=engine)
53 elif isinstance(sequence, (list, tuple)) or is_iterable(sequence):
54 self._max_repr_items = max_repr_items
55 self._base_sequence = sequence
56 self._lineage = Lineage(engine=engine)
57 else:
58 raise TypeError("Given sequence must be an iterable value")
59 if transform is not None:
60 self._lineage.apply(transform)
61
62 def __iter__(self):
63 """
64 Return iterator of sequence.
65
66 :return: iterator of sequence
67 """
68 return self._evaluate()
69
70 def __eq__(self, other):
71 """
72 Checks for equality with the sequence's equality operator.
73
74 :param other: object to compare to
75 :return: true if the underlying sequence is equal to other
76 """
77 return self.sequence == other
78
79 def __ne__(self, other):
80 """
81 Checks for inequality with the sequence's inequality operator.
82
83 :param other: object to compare to
84 :return: true if the underlying sequence is not equal to other
85 """
86 return self.sequence != other

Callers 5

_parse_argsMethod · 0.90
test_constructorMethod · 0.90
__add__Method · 0.85
_transformMethod · 0.85
_wrapFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_constructorMethod · 0.72