Args: ds (DataFlow): input dataflow size (int): size keep_state (bool): keep the iterator state of ``ds`` between calls to :meth:`__iter__()`, so that the next call will continue the previous iteration over ``ds``,
(self, ds, size, keep_state=True)
| 233 | """ Generate data from another DataFlow, but with a fixed total count. |
| 234 | """ |
| 235 | def __init__(self, ds, size, keep_state=True): |
| 236 | """ |
| 237 | Args: |
| 238 | ds (DataFlow): input dataflow |
| 239 | size (int): size |
| 240 | keep_state (bool): keep the iterator state of ``ds`` |
| 241 | between calls to :meth:`__iter__()`, so that the |
| 242 | next call will continue the previous iteration over ``ds``, |
| 243 | instead of reinitializing an iterator. |
| 244 | |
| 245 | Example: |
| 246 | |
| 247 | .. code-block:: none |
| 248 | |
| 249 | ds produces: 1, 2, 3, 4, 5; 1, 2, 3, 4, 5; ... |
| 250 | FixedSizeData(ds, 3, True): 1, 2, 3; 4, 5, 1; 2, 3, 4; ... |
| 251 | FixedSizeData(ds, 3, False): 1, 2, 3; 1, 2, 3; ... |
| 252 | FixedSizeData(ds, 6, False): 1, 2, 3, 4, 5, 1; 1, 2, 3, 4, 5, 1;... |
| 253 | """ |
| 254 | super(FixedSizeData, self).__init__(ds) |
| 255 | self._size = int(size) |
| 256 | self.itr = None |
| 257 | self._keep = keep_state |
| 258 | |
| 259 | def __len__(self): |
| 260 | return self._size |