-
-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Iterator#keepLast() to allow storing last iterator value #340
base: master
Are you sure you want to change the base?
Conversation
lib/iterator.js
Outdated
this.lastElement = undefined; | ||
} | ||
|
||
get last() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get last() { | |
last() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not like the proposed functionality as it propagates a programmer to save the iterator before the transformation. Leading to a situation where you have multiple iterators sharing a common state.
I would prefer to have a splitOn
function, that will split iterator into two.
iter([1, 2, 3, 4, 5]).splitOn(v => v >= 3); // [iter([1, 2]), iter([3, 4, 5])]
constructor(base) { | ||
super(base); | ||
this.repeat = false; | ||
this.lastElement = undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like lastElement
sound like instead of { value: T, done: boolean }
it is T
.
I think the proposed Will think about a better solution.
Though, what's wrong with this? I think it's already possible if someone wants to take values from the same iterator in multiple places (which is fine IMO) or misuses iterator (like using |
The problem is that it forces programmers to save iterator pre-transformation. |
npm run fmt
)npm run doc
to regenerate documentation based on comments)Unreleased
header in CHANGELOG.md