RxRuby
RxRuby copied to clipboard
Change order of parameters on Observable.while
@jca02266 should we change the order of the parameter on #while so that we could use a block instead?
require 'rx'
i = 0
# Repeat until condition no longer holds
source = RX::Observable.while(RX::Observable.just 42) { i += 1; i <= 3 }
subscription = source.subscribe(
lambda {|x|
puts 'Next: ' + x.to_s
},
lambda {|err|
puts 'Error: ' + err.to_s
},
lambda {
puts 'Completed'
})
# => Next: 42
# => Next: 42
# => Next: 42
# => Completed
It seems like: while(condition) { action } but not,
IMHO, change the method name to something for ruby way. We must careful to use block.
How about yield_while instead?
We can accept block without changing parameter order
--- a/lib/rx/linq/observable/while.rb
+++ b/lib/rx/linq/observable/while.rb
@@ -1,6 +1,13 @@
module RX
class <<Observable
- def while(condition, source)
+ def while(condition_or_source, source = nil)
+ if block_given?
+ condition = Proc.new
+ source = condition_or_source
+ else
+ condition = condition_or_source
+ end
+
enum = Enumerator.new {|y|
while condition.call
y << source
We have many time considering it
How about yield_while instead?
Hmm.