-
Notifications
You must be signed in to change notification settings - Fork 604
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
Iterator Handling in IO Package #978
Iterator Handling in IO Package #978
Conversation
io/src/main/scala/fs2/io/io.scala
Outdated
/** | ||
* Reads all the values of the iterator into a Stream. | ||
*/ | ||
def readIterator[F[_], A](iterator: Iterator[A])(implicit F: Effect[F]): Stream[F, A] = { |
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 think we can move this method to Stream
companion as Stream.fromIterator
-- the effect constraint can be loosened to Sync
.
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.
You can make this a bit more concise with:
def readIterator2[F[_], A](iterator: Iterator[A])(implicit F: Sync[F]): Stream[F, A] =
Stream.unfoldEval(iterator)(i => F.delay(i.hasNext.guard[Option].as(i.next -> i)))
it's a style choice though, so up to you
io/src/main/scala/fs2/io/io.scala
Outdated
/** | ||
* Brackets Resource Acquisition for an Iterator | ||
*/ | ||
def readBracketedIterator[F[_]: Effect, R, O](acquire: F[R]) |
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'm not convinced we need this method. If we have Stream.fromIterator
, I think putting that together with Stream.bracket
is simple enough.
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'm also a bit unconvinced we need this, especially because the user still has to do some massaging to get an R => F[Iterator[O]]
(the wrapping in F
), at which point one could use bracket
directly
io/src/main/scala/fs2/io/io.scala
Outdated
/** | ||
* Reads all the values of the iterator into a Stream. | ||
*/ | ||
def readIterator[F[_], A](iterator: Iterator[A])(implicit F: Effect[F]): Stream[F, A] = { |
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.
You can make this a bit more concise with:
def readIterator2[F[_], A](iterator: Iterator[A])(implicit F: Sync[F]): Stream[F, A] =
Stream.unfoldEval(iterator)(i => F.delay(i.hasNext.guard[Option].as(i.next -> i)))
it's a style choice though, so up to you
Moves package to Stream companion object, removes the bracketed component, in favor of using bracket directly, and switches to guard notation
Fixes #971
If you are interested in this being implemented. It used to be present in scalaz-stream, and is a useful piece of functionality. If there is a problem in this implementation I would like to know so I can avoid it.