Creates a stream by repeatedly calling a lazily evaluated function#1139
Conversation
hearnadam
left a comment
There was a problem hiding this comment.
Thanks for your contribution! This definitely could be useful.
| Emit.valueWith(c.take(_chunkSize))(Loop.continue(c.dropLeft(_chunkSize))) | ||
| v.map(seq => emitResized(seq, chunkSize)) | ||
|
|
||
| private def emitResized[V](seq: Seq[V], chunkSize: Int)(using tag: Tag[Emit[Chunk[V]]], frame: Frame): Unit < Emit[Chunk[V]] = |
There was a problem hiding this comment.
I don't think this is quite semantically correct for the repeat case as it may produce chunks like this:
given: repeatPresent(Chunk(1, 2, 3, 4), 3)
outcome: Stream(Chunk(1, 2, 3), Chunk(4), Chunk(1, 2, 3), Chunk(4)...)
In my opinion, it's reasonable for .rechunk to be used after the repeat operator, given rechunking will happen across suspension.
There was a problem hiding this comment.
Thanks for the reply. I've changed to calling rechunk.
| } | ||
|
|
||
| "repeatPresent" - { | ||
| var i = 0 |
There was a problem hiding this comment.
Please avoid mutability outside the scope of a single test if possible 🙏 it makes parallelizing/refactoring tests difficult.
Perhaps you can use the Var effect?
…ntil the return is absent.
56b6ed8 to
57b9653
Compare
|
thank you @vladpo! |
…1139) Creates a stream by repeatedly calling a lazily evaluated function, until the return is absent. <!-- PRs require an approval from any of the core contributors, other than the PR author. Include this header if applicable: Fixes #issue1, #issue2, ... --> ### Problem <!-- Explain here the context, and why you're making this change. What is the problem you're trying to solve? --> Stream emit an effect until some end state offers no more values. ### Solution <!-- Describe your solution. Focus on helping reviewers understand your technical approach and implementation decisions. --> repeatPresent is a factory method in the Stream class that creates a stream by repeatedly calling a function until it returns an absent value 1. Create a stream from a function that may return values multiple times 2. Automatically terminate the stream when the function returns an absent value 3. Control the chunk size of emitted values for performance optimization ### Notes <!-- Add any important additional information as bullet points, such as: - Implementation details reviewers should know about - Open questions and concerns - Limitations -->
Creates a stream by repeatedly calling a lazily evaluated function, until the return is absent.
Problem
Stream emit an effect until some end state offers no more values.
Solution
repeatPresent is a factory method in the Stream class that creates a stream by repeatedly calling a function until it returns an absent value
Notes