Skip to content

Commit

Permalink
doc: Update
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmah309 committed Dec 9, 2024
1 parent b284d98 commit 76d2826
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void main() {
break;
case ["!", _]:
answer.push(index);
case [_, "!"] when iter.peek().isNone():
case [_, "!"] when iter.peek() == null: // or `iter.peekOpt().isNone()`
answer.push(index + 1);
}
}
Expand Down
11 changes: 6 additions & 5 deletions test/iter/iter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1160,19 +1160,20 @@ main() {

test("Use case example 6", () {
/// Get the index of every "!" in a string not followed by a "?"
List<int> answer = [];
String string = "kl!sd!?!";
final string = "kl!sd!?!";
Vec<int> answer = [];
Peekable<(int, Arr<String>)> iter =
string.chars().mapWindows(2, identity).enumerate().peekable();

while (iter.moveNext()) {
final (index, window) = iter.current;
switch (window) {
case ["!", "?"]:
break;
case ["!", _]:
answer.add(index);
case [_, "!"] when iter.peekOpt().isNone():
answer.add(index + 1);
answer.push(index);
case [_, "!"] when iter.peek() == null:
answer.push(index + 1);
}
}
expect(answer, [2, 7]);
Expand Down

0 comments on commit 76d2826

Please sign in to comment.