Counterintuitive behavior in take
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.2k
- Forks
- 280
- Avg merge
- 6d 17h
- Merged PRs (30d)
- 4
Description
I think the following should be at least documented. When the seq argument to take is an iterator (as opposed to a sequence; toolz's use of the word "sequence" is inconsistent with the Python stdlib), it doesn't force evaluation of the first n elements, so if the result is not fully evaluated by the caller, the elements it is supposed to "take" are still in the iterator.
>>> it = iter([1, 2, 3])
>>> first2 = take(2, it)
>>> list(it)
[1, 2, 3]
>>> list(first2)
[]
vs.
>>> it = iter([1, 2, 3])
>>> list(take(2, it))
[1, 2]
>>> list(it)
[3]
I know this is a consequence of using islice, but it's surprising if you expect the behavior of Haskell's take.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the take entry point and the iterator examples in this issue; review how the current documentation describes evaluation behavior. Update the documentation to explain the difference between creating the result and consuming it, including the shown iterator examples. Done when users can understand whether the input iterator has advanced before evaluating the returned result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100