Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change order of parameters on Observable.while #52

Open
mattpodwysocki opened this issue Dec 31, 2014 · 4 comments
Open

Change order of parameters on Observable.while #52

mattpodwysocki opened this issue Dec 31, 2014 · 4 comments

Comments

@mattpodwysocki
Copy link
Contributor

@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
@jca02266
Copy link
Contributor

It seems like:
while(condition) { action }
but not,

IMHO, change the method name to something for ruby way.
We must careful to use block.

@mattpodwysocki
Copy link
Contributor Author

How about yield_while instead?

@jca02266
Copy link
Contributor

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

@jca02266
Copy link
Contributor

How about yield_while instead?

Hmm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants