-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a934e00
commit 9c43cf8
Showing
4 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
package org.lemon.advent.lib | ||
|
||
extension [A](it: Iterator[A]) | ||
/** Returns the nth element of the iterator. | ||
* | ||
* @param n the index of the element to return | ||
* @throws NoSuchElementException if there is no nth element | ||
* @return the nth element of the iterator | ||
*/ | ||
def nth(n: Int): A = it.drop(n).next | ||
|
||
/** Returns the nth element of the iterator, or None if there is no nth element. | ||
* | ||
* @param n the index of the element to return | ||
* @return the nth element of the iterator, or None if there is no nth element | ||
*/ | ||
def nthOption(n: Int): Option[A] = it.drop(n).nextOption |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters