File: operators.rst

package info (click to toggle)
python-aiostream 0.5.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 368 kB
  • sloc: python: 2,445; makefile: 5
file content (174 lines) | stat: -rw-r--r-- 3,096 bytes parent folder | download | duplicates (3)
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
Stream operators
================

.. module:: aiostream.stream

The stream operators produce objects of
the `Stream <core.html#stream-base-class>`_ class.

They are separated in 7 categories:

.. include:: table.rst.inc

They can be found in the :mod:`aiostream.stream` module.

Custom stream operators can be created using the `@operator <core.html#operator-decorator>`_ decorator.


Pipe-lining
-----------

Most of the operators have a :meth:`pipe` method corresponding to their equivalent pipe operator.
They are also gathered and accessible through the :mod:`aiostream.pipe` module.
The pipe operators allow a 2-step instantiation.

For instance, the following stream::

  ys = stream.map(xs, lambda x: x**2)

is strictly equivalent to::

  ys = pipe.map(lambda x: x**2)(xs)

and can be written as::

  ys = xs | pipe.map(lambda x: x**2)

This syntax comes in handy when several operators are chained::

  ys = (xs
      | pipe.operator1(*args1)
      | pipe.operator2(*args2)
      | pipe.operator3(*args3))


Creation operators
------------------

.. note:: Those operators do not have a pipe equivalent.

.. autoclass:: iterate

.. autoclass:: preserve

.. autoclass:: just

.. autoclass:: call

.. autoclass:: empty

.. autoclass:: throw

.. autoclass:: never

.. autoclass:: repeat

.. autoclass:: range

.. autoclass:: count


Transformation operators
------------------------

.. autoclass:: map

   .. note:: :class:`map` is considered a combination operator
	     if used with extra sources, and a transformation operator otherwise

.. autoclass:: enumerate

.. autoclass:: starmap

.. autoclass:: cycle

.. autoclass:: chunks

Selection operators
-------------------

.. autoclass:: take

.. autoclass:: takelast

.. autoclass:: skip

.. autoclass:: skiplast

.. autoclass:: getitem

.. autoclass:: filter

.. autoclass:: until

.. autoclass:: takewhile

.. autoclass:: dropwhile

Combination operators
---------------------

.. autoclass:: map

   .. note:: :class:`map` is considered a combination operator
	     if used with extra sources, and a transformation operator otherwise

.. autoclass:: zip

.. autoclass:: merge

.. autoclass:: chain

.. autoclass:: ziplatest


Aggregatation operators
-----------------------

.. autoclass:: accumulate

.. autoclass:: reduce

.. autoclass:: list


Advanced operators
------------------

.. note:: The :class:`concat`, :class:`flatten` and :class:`switch` operators
   all take a **stream of streams** as an argument (also called **stream of
   higher order**) and return a flattened stream using their own merging
   strategy.

.. autoclass:: concat

.. autoclass:: flatten

.. autoclass:: switch

.. note:: The :class:`concatmap`, :class:`flatmap` and :class:`switchmap` operators
   provide a simpler access to the three merging strategy listed above.

.. autoclass:: concatmap

.. autoclass:: flatmap

.. autoclass:: switchmap


Timing operators
----------------

.. autoclass:: spaceout

.. autoclass:: timeout

.. autoclass:: delay


Miscellaneous operators
-----------------------

.. autoclass:: action

.. autoclass:: print