-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 LazyList tailRecM using Iterator.unfold #2964
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2964 +/- ##
==========================================
+ Coverage 93.91% 93.93% +0.02%
==========================================
Files 371 371
Lines 7061 7061
Branches 177 177
==========================================
+ Hits 6631 6633 +2
+ Misses 430 428 -2
Continue to review full report at Codecov.
|
1 similar comment
Codecov Report
@@ Coverage Diff @@
## master #2964 +/- ##
==========================================
+ Coverage 93.91% 93.93% +0.02%
==========================================
Files 371 371
Lines 7061 7061
Branches 177 177
==========================================
+ Hits 6631 6633 +2
+ Misses 430 428 -2
Continue to review full report at Codecov.
|
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.
cool! thanks!
val b = o.get | ||
advance() | ||
b | ||
val kernel = Iterator.unfold[Option[B], Iterator[Either[A, B]]](Iterator(Left(a))) { it => |
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.
two small notes, I bet this would be faster if we did:
unfold[Option[B], List[Iterator[Either[A, B]]])(Iterator.single(Left(a)) :: Nil) {
case Nil => None
case nonempty@(h :: t) =>
if (!h.hasNext) Some((None, t))
else h.next match {
case Left(a) => Some((None, fn(a) :: nonempty))
case Right(b) => Some((Some(b), nonempty))
}
}
Implements
LazyList
'stailRecM
usingIterator.unfold
.