Repository navigation
Refactor/simplify avoid duplicate code #348
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
Changes from 1 commit
8c187fc
9d67cdc
9675840
f2d3998
5002960
716d97e
6df48fa
8a6b23a
b3e2958
57865ff
45586c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…-avoid-duplicate-code
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,19 @@ extension TokenUtils on Token { | |
| yield c; | ||
| } | ||
| } | ||
|
|
||
| /// Returns an iterable sequence of tokens starting from this token up to | ||
| /// (and including) [end]. | ||
| Iterable<Token> upTo(Token end) sync* { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can extract a function that we can reuse for other cases where we are generating an iterable from iterator like objects: Iterable<Token> upTo(Token end) => generate(
this,
(e) => e == end || e.next == e ? null : e.next,
);
}
Iterable<T> generate<T>(T seed, T? Function(T) next) sync* {
var current = seed;
while (true) {
yield current;
final n = next(current);
if (n == null) break;
current = n;
}
}
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! |
||
| var current = this; | ||
| while (true) { | ||
| yield current; | ||
| if (current == end) break; | ||
| final next = current.next; | ||
| if (next == null || next == current) break; | ||
| current = next; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Extension methods for [Iterable<Token>] manipulation. | ||
|
|
||
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.
not really sure why we are changing this
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 added upTo to support ignore comments for cases like:
Also simplified the function: