ReactiveX/Rx.rb

View on GitHub
examples/default_if_empty.rb

Summary

Maintainability
A
0 mins
Test Coverage
require 'rx'

#  Without a default value
source = Rx::Observable.empty.default_if_empty

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

# => Next: nil
# => Completed

#  With a default_value
source = Rx::Observable.empty.default_if_empty(false)

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

# => Next: false
# => Completed