Skip to content

Commit

Permalink
added description for itertools_mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
kaliv0 committed Nov 7, 2024
1 parent 4bc06cd commit 015c0de
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ Stream([1, 2, 3]).reduce(lambda acc, val: acc + val, identity=3).get()
.to_list())
```

- view
<br>(provides access to a selected part of the stream)
```python
Stream([1, 2, 3, 4, 5, 6, 7, 8, 9]).view(start=1, stop=-3, step=2).to_list()
```
```shell
[2, 4, 6]
```

- distinct
<br>(returns a stream with the distinct elements of the current one)
```python
Expand Down Expand Up @@ -308,15 +317,22 @@ Stream([2, 3, 4, 5, 6]).quantify(predicate=lambda x: x % 2 == 0)
```
--------------------------------------------
### Itertools integration
Invoke <i>use</i> method by passing the itertools function and it's arguments as **kwargs
```python
import itertools
import operator

Stream([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).use(itertools.islice, start=3, stop=8)
Stream.of(1, 2, 3, 4, 5).use(itertools.accumulate, func=operator.mul).to_list()
Stream(range(3)).use(itertools.permutations, r=3).to_list()

```
#### Itertools 'recipes'
- tee
Invoke the 'recipes' described [here](https://docs.python.org/3/library/itertools.html#itertools-recipes) as stream methods and pass required key-word arguments
```python
Stream([1, 2, 3]).ncycles(count=2).to_list()
Stream.of(2, 3, 4).take_nth(10, default=66).get()
Stream(["ABC", "D", "EF"]).round_robin().to_list()
```
--------------------------------------------
### Querying files with FileStream
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pyrio"
version = "1.1.0"
version = "1.1.1"
authors = ["kaliv0 <[email protected]>"]
readme = "README.md"
description = "Functional-style Streams library for processing collections and querying files (json, toml, yaml, xml, csv, tsv). Provides easy integration with itertools."
Expand Down
2 changes: 1 addition & 1 deletion pyrio/itertools_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _handle_default_signature_functions(self, signature, it_function, **kwargs):
# ### 'recipes' ###
# https://docs.python.org/3/library/itertools.html#itertools-recipes
def tabulate(self, mapper, start=0):
""" "Returns function(0), function(1), ..."""
"""Returns function(0), function(1), ..."""
self._iterable = map(mapper, it.count(start))
return self

Expand Down

0 comments on commit 015c0de

Please sign in to comment.