You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add raw option to head(), head_option(), first(), last() and last_option()
* Rename raw to no_wrap; improvements
* Make pylint happier
* Fix code formatting
* Increase code coverage
* Add `no_wrap` option to `head()`, `head_option()`, `first()`, `last()` and `last_option()`, as well as to `seq()`, `pseq()` and `Sequence` constructor
4
5
5
6
## Release 1.3.0
6
7
* added precompute attribute to reverse transformation (#137)
Copy file name to clipboardExpand all lines: README.md
+28-4Lines changed: 28 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -362,10 +362,10 @@ Function | Description | Type
362
362
`sorted(key=None, reverse=False)/order_by(func)` | Returns elements sorted according to python `sorted` | transformation
363
363
`reverse()` | Returns the reversed sequence | transformation
364
364
`slice(start, until)` | Sequence starting at `start` and including elements up to `until` | transformation
365
-
`head()` / `first()` | Returns first element in sequence | action
366
-
`head_option()` | Returns first element in sequence or `None` if its empty | action
367
-
`last()` | Returns last element in sequence | action
368
-
`last_option()` | Returns last element in sequence or `None` if its empty | action
365
+
`head(no_wrap=None)` / `first(no_wrap=None)` | Returns first element in sequence (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action
366
+
`head_option(no_wrap=None)` | Returns first element in sequence or `None` if its empty (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action
367
+
`last(no_wrap=None)` | Returns last element in sequence (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action
368
+
`last_option(no_wrap=None)` | Returns last element in sequence or `None` if its empty (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action
369
369
`len()` / `size()` | Returns length of sequence | action
370
370
`count(func)` | Returns count of elements in sequence where `func(element)` is True | action
371
371
`empty()` | Returns `True` if the sequence has zero length | action
@@ -443,6 +443,30 @@ Files are given special treatment if opened through the `seq.open` and related A
443
443
multiple iteration over a single file object while correctly handling iteration termination and
444
444
file closing.
445
445
446
+
### `no_wrap` option
447
+
Even though functions like `first()` are supposed to return a single element, if the element is an iterable,
448
+
then it is wrapped into a `Sequence`. For instance:
449
+
450
+
```
451
+
>>> s = seq(list(), list())
452
+
>>> type(a.first())
453
+
<class 'functional.pipeline.Sequence'>
454
+
```
455
+
456
+
That behaviour can be changed with `no_wrap` option:
457
+
458
+
```
459
+
>>> type(a.first(no_wrap=True))
460
+
<class 'list'>
461
+
```
462
+
463
+
The option is also accpeted by `seq()`/`pseq()` as well as `Sequence()` constructor, for example:
0 commit comments