https://kotlinlang.org logo
#android
Title
# android
k

kirillrakhman

03/14/2017, 10:19 PM
Streams for sure
l

lupajz

03/14/2017, 10:24 PM
Is there even a use case, for which one would prefer Streams over Rx Observables ?
k

kirillrakhman

03/14/2017, 10:27 PM
Sure, they are very different things
Parallel execution for example
l

lupajz

03/14/2017, 10:29 PM
I know they are very different in nature. Parallel is now in form of ParallelFlowable. But I was wondering if you know any real use case for that ? Because I don’t see any
f

frank

03/14/2017, 10:47 PM
Anytime you're working with a normal list I'd say. You can turn
Copy code
List<String> items = ...
List<String> result = new ArrayList()
for (String item : items) {
    if (item.startsWith('42')) {
        result.add(item)
    }
}
into
Copy code
List<String> items = ...
List<String> result = items.stream().
    .filter(item -> item.startswith('42'))
    .collect(Collectors.toList());
Sometimes wrapping something in RxJava before using it can be a bit overkill imo. (It feels like there should also be a performance difference, but I'm not sure on that). Plus not every project might actually have a use for RxJava, and this way you have one less dependency.
👍 1
3 Views