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.
ArrayObservable
usesarray_shift
instead of an index to access the current value, which makes it about 10 times slower thanfromArray
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 ofarray_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.