Skip to content
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

Add Source.interleaveAll combinator #13

Merged
merged 3 commits into from
Oct 6, 2023
Merged

Add Source.interleaveAll combinator #13

merged 3 commits into from
Oct 6, 2023

Conversation

rucek
Copy link
Contributor

@rucek rucek commented Oct 5, 2023

No description provided.

@rucek rucek requested a review from adamw October 5, 2023 13:28
@rucek rucek force-pushed the source-interleave-all branch from 96ec633 to 895ba96 Compare October 5, 2023 13:35
* scala> val res0: List[Int] = List(1, 2, 10, 20, 100, 200, 3, 4, 30)
* }}}
*/
def interleaveAll[U >: T](others: Seq[Source[U]], segmentSize: Int = 1, eagerComplete: Boolean = false)(using
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since none of the sources is special, maybe this shoul dbe a method on Source - Source.interlaveAll?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One downside is that this would require us to handle the case of an empty list - but then I think we just return a done source.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point with moving it to Source. As for the empty list - we can either return a done source as you suggest, or change the signature of interleaveAll so that it enforces at least two sources (since one source would be a special case as well, where we just return the argument), e.g.

def interleaveAll[T](first: Source[T], second: Source[T], rest: Source[T]*)(segmentSize: Int, eagerComplete: Boolean)

The downside of the latter approach would be making the API inconsistent between interleave and interleaveAll. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's an inconsistency, interleave acts on two sources using the more convenient dot-notation, the ...All variant takes an arbitrary list. The first / second approach would be good, but then it enforces static structure - won't work if you have a dynamically-defined list of sources.

Copy link
Member

@adamw adamw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One suggestion, otherwise ok :)

@rucek rucek requested a review from adamw October 6, 2023 12:26
@adamw adamw merged commit 8efe299 into master Oct 6, 2023
@adamw adamw deleted the source-interleave-all branch February 21, 2024 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants