Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Adding #drop support.
Pretty straightforward.
- Loading branch information
1 parent
a678f7f
commit c844efb73b40353f9c9362bcffa86e1d28ff45e0
Showing
3 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| module Frappuccino | ||
| class Drop < Stream | ||
| def initialize(source, n) | ||
| source.add_observer(self) | ||
|
|
||
| @count = 0 | ||
| @dropped = 0 | ||
| @n = n | ||
| end | ||
|
|
||
| def update(event) | ||
| @dropped += 1 | ||
|
|
||
| if @dropped > @n | ||
| occur(event) | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| require 'test_helper' | ||
|
|
||
| describe "drop" do | ||
| it "ignores the first n events" do | ||
| button = Button.new | ||
|
|
||
| stream = Frappuccino::Stream.new(button) | ||
| dropped_stream = stream.drop(3) | ||
|
|
||
| 5.times { button.push } | ||
|
|
||
| assert_equal 2, dropped_stream.count | ||
| end | ||
| end |