Giter Site home page Giter Site logo

Comments (10)

dbrattli avatar dbrattli commented on May 18, 2024

Thanks for pointing this out. That code looks ugly.

from rxpy.

trilokacharya avatar trilokacharya commented on May 18, 2024

Thanks for jumping on it so quickly. Any idea when this would get merged into master?

from rxpy.

dbrattli avatar dbrattli commented on May 18, 2024

I don't have code that triggers the bug, so it's hard for me to know if really fixes the bug. If you could verify the fix, or post some minimal code that triggers the bug, then I can make a unit-test. When we know the fix is correct, then I can merge to master.

from rxpy.

38elements avatar 38elements commented on May 18, 2024

Hi, @dbrattli
Hi, @trilokacharya
I tried this by using Python 2.7 and RxPY 1.1.
I reproduced the bug in RxPY 1.1 with the code below and I also confirmed the 72eecb fixes the problem.

from __future__ import print_function
import rx

s = rx.Observable.range(0, 5)
rx.Observable.zip_array(
    s,
    s.skip(1),
    s.skip(2)
).subscribe(print)

result

  File "/usr/local/lib/python2.7/dist-packages/rx/linq/observable/ziparray.py", line 82, in action
    queues[n] = []
IndexError: list assignment index out of range

from rxpy.

dbrattli avatar dbrattli commented on May 18, 2024

The code in Observable.zip and Observable.zip_arraylooks very similar. What is really the difference between zip_arrayand zip(s1, s2, lambda: x, y: [x, y]) @mattpodwysocki ? I checked the JavaScript sources, and they still have both operators Observable.zipArrayand observableProto.zip that are very similar. Would be nice if we could refactor this code, and implement zip_array (or really zip_list in python) just using zip.

from rxpy.

trilokacharya avatar trilokacharya commented on May 18, 2024

@dbrattli, my understanding from reading the docs at http://reactivex.io/documentation/operators/zip.html is that zip_array is supposed to take a variable number of observables and zip them all.

This is not pretty, but I think it shows the intended behavior:

# Note: please excuse the formatting errors. I can't figure out how to get my formatting to stick in Markup
def flat_add(a,b):
        """ if a = valueA, b = valueB : returns [valueA, valueB]. 
            if a = [V1,V2..Vn], b = valueB : returns [V1,V2..Vn,valueB ]
        """
    if isinstance(a,list):
               a.append(b)
               return a
    else:
               return [a,b]

s1 = rx.Observable.range(0, 5)
s2 = s1.skip(1)
s3 = s1.skip(2)

reduce(lambda a,b:a.zip(b,flat_add),[s1,s2,s3])

"""
result = 
[0, 1, 2]
[1, 2, 3]
[2, 3, 4]
""""

from rxpy.

dbrattli avatar dbrattli commented on May 18, 2024

Yes, but you can do that already with zip:

>>> import rx
>>> def res(*args):
...    return list(args)
...
>>> s1 = rx.Observable.range(0, 5)
>>> s2 = s1.skip(1)
>>> s3 = s1.skip(2)
>>> rx.Observable.zip(s1, s2, s3, res).subscribe(print)
[0, 1, 2]
[1, 2, 3]
[2, 3, 4]
<rx.autodetachobserver.AutoDetachObserver object at 0x1025c1320>

Isn't this the same?

from rxpy.

trilokacharya avatar trilokacharya commented on May 18, 2024

You're right. I should've read the description better instead of just looking at the diagram and thinking zip only works on 2 observables at a time.

from rxpy.

dbrattli avatar dbrattli commented on May 18, 2024

I've now added the simplified Observable.zip_array to the develop branch.

from rxpy.

lock avatar lock commented on May 18, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

from rxpy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.