ReactiveX/Rx.rb

View on GitHub
examples/buffer_with_count.rb

Summary

Maintainability
A
0 mins
Test Coverage
require 'rx'

#  Without a skip
source = Rx::Observable.range(1, 6)
    .buffer_with_count(2)

subscription = source.subscribe(
    lambda {|x|
        puts 'Next: ' + x.to_s
    },
    lambda {|err|
        puts 'Error: ' + err.to_s
    },
    lambda {
        puts 'Completed'
    })

# => Next: [1, 2]
# => Next: [3, 4]
# => Next: [5, 6]
# => Completed

#  Using a skip
source = Rx::Observable.range(1, 6)
    .buffer_with_count(2, 1)

subscription = source.subscribe(
    lambda {|x|
        puts 'Next: ' + x.to_s
    },
    lambda {|err|
        puts 'Error: ' + err.to_s
    },
    lambda {
        puts 'Completed'
    })

# => Next: [1, 2]
# => Next: [2, 3]
# => Next: [3, 4]
# => Next: [4, 5]
# => Next: [5, 6]
# => Next: [6]
# => Completed