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

Implement #zip for Stream #9

Merged
merged 2 commits into from Apr 27, 2013
Merged

Conversation

seadowg
Copy link
Contributor

@seadowg seadowg commented Apr 26, 2013

This operation takes a stream and zips the receiver and the argument together. This essentially results in a Stream that doesn't occur until both input streams have and will contain events that are tuples of corresponding input events (so [left_event, right_event]). This means that we have #merge to create a stream that occurs whenever either inputs occur and #zip for when both have occurred (sort of like and & and | for Streams in a way).

This actually introduces a small performance problem as zipping one stream that occurs very rarely with another that occurs frequently will cause the latter to buffer a lot and so it will consume a lot of memory.

P.S. This #zip operation only allows you to zip two streams together at the moment. If we wanted the Stream API to be interchangeable with Enumerable it will need to take an arbitrary number of streams. For the moment though I felt this provided a nice amount of functionality.

This operation takes another stream and zips the receiver and the
argument together. This essentially results in a Stream that doesn't
occur until both input streams have and will contain events that are
tuples of corresponding input events.
@right_buffer = []
left.add_observer(self, :left_update)
right.add_observer(self, :right_update)
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Create buffers for each 'side' of the operation and set up an observers that call custom methods.

steveklabnik added a commit that referenced this pull request Apr 27, 2013
Implement #zip for Stream
@steveklabnik steveklabnik merged commit 1019dad into steveklabnik:master Apr 27, 2013
@steveklabnik
Copy link
Owner

Have I mentioned lately how much I enjoy the line-by-line play-by-play in your PRs? Thanks!

@seadowg
Copy link
Contributor Author

seadowg commented Apr 27, 2013

No problem! I love the per line commit tool. Really helps me explain my changes without a lot of prose.

On Fri, Apr 26, 2013 at 6:32 PM, Steve Klabnik notifications@github.com
wrote:

Have I mentioned lately how much I enjoy the line-by-line play-by-play in your PRs? Thanks!

Reply to this email directly or view it on GitHub:
#9 (comment)

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.

None yet

2 participants