-
Couldn't load subscription status.
- Fork 1.4k
Implement ZStream#intersperse #3514
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
Conversation
|
Let's make this a transducer instead, right? Then it's just a fold that inserts the element every even one: state.modify { flag =>
os.foldRight(Nil -> flag) {
case (o, (out, true)) => (a :: o :: out) -> false
case (o, (out, false)) => (o :: out) -> true
}
} |
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.
Looks great. One small comment.
| /** | ||
| * Intersperse stream with provided element similar to <code>List.mkString</code>. | ||
| */ | ||
| final def intersperse[O1 >: O](middle: O1): ZStream[R, E, O1] = |
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.
@fagossa Could we add a variant that also adds start/end markers? This could simply be ZStream(start) ++ intersperse(middle) ++ ZStream(end).
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.
done!
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.
Awesome contribution @fagossa. Super useful operator. Thank you!
This is an implementation for
intersperse(#3440).For example: