steveklabnik/frappuccino — pull request #13 by seadowg (2013-05-01 05:13:23+00:00)
Title: Add #take and to_array

This adds an implementation for Enumerable#take for Stream (takes a number n and returns a Stream that will stop occurring after n events). There might be some optimisations we could make to the implementation of this as callbacks and observers could all be cleaned up after the Stream 'finishes' but I've kept it simple for now.

I've also added a helper method `to_array` for testing that takes a Stream and returns a Ruby array representation of the contents (that stays up to date). All this really does is bind a callback to the stream that pushes occurrences into the returned array. This seemed to be how we were testing many of the operations for Stream and it seems to help make the tests more concise.