-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Support Observable.from(array_of_primitives) #3518
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
Comments
Could not you just use |
There's a gotcha with this approach. I can use third-party library, like Guava and have |
We named it just. |
A proper support would require specializing RxJava types to primitive types which is quite cumbersome for minimal benefit. |
I probably didn't make myself clear. I'd like to have an option to observe a sequence of characters in a String, so that: char[] chars = "some string".toCharArray();
Observable.from(chars).subscribe(curr -> System.out.println("next: " + curr)); //currently does not compile outputs:
The options you mentioned work the following way: Observable.from(Arrays.asList(chars)).subscribe(curr -> System.out.println("next: " + curr)); outputs:
and the same for the other case Observable.just(chars).subscribe(curr -> System.out.println("next: " + curr)); outputs:
|
char[] chars = "string".toCharArray();
Observable.range(0, chars.length).map(i -> chars[i]).subscribe(...) |
@akarnokd I can understand it as long as it's a conscious decision. Note however that without this support it's easy to fall for a trap, such as: Observable.from(Arrays.asList(chars)) which as described above does not do what might seem most intuitive.
|
@akarnokd regarding your example - sure, it's doable, I'm just asking to facilitate usage. |
Such source factory methods doesn't have to be on the |
Another way to do it: |
It seems that it is currently impossible to create an
Observable
from an array of primitives, e.g.:Is this a conscious decision?
The text was updated successfully, but these errors were encountered: