RxRuby
RxRuby copied to clipboard
Generate
Should we switch from using Procs ala this for Observable::generate?:
RX::Observable.generate(
0,
Proc.new { |x| return x <= 3 },
Proc.new { |x| return x + 1 },
Proc.new { |x| return x },
scheduler)
to this style?
Observable.generate do
initial_state 0
condition {|x| x <= 3}
result_selector {|x| x + 1}
iterator {|x| x }
scheduler RX::TestScheduler.new
end
# OR
Observable.generate do
initial_state 0
iterate_while {|x| x <= 3}
select_result_with {|x| x + 1}
iterate_with {|x| x }
scheduler RX::TestScheduler.new
end
I definitely prefer the newer style and I like the 2nd generate
with iterate_with
, etc.
There's a lot more clarity with the second example and much more succintness with the first. I personally prefer the succintness.
I might suggest a style that fits more closely e.g. with how Enumerators behave:
Observable.generate(0, RX::TestScheduler.new)
.iterate { |x| x } # Identity as iterator could be the default
.while { |x| x <= 3 }
.select { |x| x + 1 }
I prefer that last one. Giving a fluid interface to the whole thing