This is a question asked in the RXJS Gitter channel but no one answers it so I post it here, hoping to have an explanation.
Hi everyone,
I am a Java developer who tries to learn rxjs. I have a dumb question about an
Observabledeclaration. To make my life easier I told myself that working withObservableis like working with the JavaStreamapi (even ifStreamis a pull base model). The example that disturbes me is this one: In java I haveInteger[] intArray = new Integer[] {1, 2, 3, 4, 5}; Stream<Integer> stream = Arrays.stream(intArray); // Here we have a stream of Integer not a Stream of Integer[], the array is flattenWith rxjs if I do this:
const intArray = [1, 2, 3, 4, 5] const intObs: Observable<number> = of(intArray); // The compiler complains, I have to change Observable<number> to Observable<number[]>It's a bit disturbing, why the
of(...)method does not flat the array? Also, if we subscribe to an observable ofObservable<number[]>why the received values are not of typenumber[]but of typenumber? I am a bit confused. Thanks for some explanation