asm89 / Rx.PHP

Reactive extensions for PHP.
MIT License
205 stars 24 forks source link

ArrayObservable and fromArray Inconsistencies #26

Closed davidwdan closed 8 years ago

davidwdan commented 8 years ago

ArrayObservable uses array_shift instead of an index to access the current value, which makes it about 10 times slower than fromArray

I can't think of any reasons why we should have both implementations. The static method should return a new instance of ArrayObservable, which should use the index instead of array_shift.

Another issue, is that fromArray only works with a numeric index. If you use an associative array, it fails.

We should use array_keys to get the actual keys, and then do this: $observer->onNext($array[$keys[$count]]);

The key will be lost, which will be okay in most cases. If you need to preserve the keys, you can use the pairs operator.