RxRuby icon indicating copy to clipboard operation
RxRuby copied to clipboard

Generate

Open mattpodwysocki opened this issue 11 years ago • 4 comments

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

mattpodwysocki avatar Feb 16 '14 22:02 mattpodwysocki

I definitely prefer the newer style and I like the 2nd generate with iterate_with, etc.

aglover avatar Jun 04 '14 20:06 aglover

There's a lot more clarity with the second example and much more succintness with the first. I personally prefer the succintness.

sunnyrjuneja avatar Oct 16 '14 22:10 sunnyrjuneja

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 }

wuest avatar Mar 30 '15 18:03 wuest

I prefer that last one. Giving a fluid interface to the whole thing

jredville avatar Dec 01 '15 19:12 jredville