davidmoten / rxjava-extras

Utilities for use with rxjava
Apache License 2.0
269 stars 27 forks source link

why use .isEmpty() ?? #21

Closed maslick closed 7 years ago

maslick commented 7 years ago

I don't understand why do I have to use .isEmpty() ? It's not obvious to me, let alone to the code reader.

Observable.just(10, 5, 2, -1, -2, -5, -1, 2, 5, 6)
    .compose(Transformers.toListWhile( 
        (list, t) -> list.isEmpty() 
            || Math.signum(list.get(0)) < 0 && Math.signum(t) < 0
            || Math.signum(list.get(0)) >= 0 && Math.signum(t) >= 0)
    .forEach(System.out::println);
davidmoten commented 7 years ago

You can't call list.get (0) if the list is empty.

On Wed, 1 Feb 2017, 08:35 Pavel Maslov notifications@github.com wrote:

I don't understand why do I have to use .isEmpty() ? It's not obvious to me, let alone to the code reader.

Observable.just(10, 5, 2, -1, -2, -5, -1, 2, 5, 6) .compose(Transformers.toListWhile( (list, t) -> list.isEmpty() || Math.signum(list.get(0)) < 0 && Math.signum(t) < 0 || Math.signum(list.get(0)) >= 0 && Math.signum(t) >= 0) .forEach(System.out::println);

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/davidmoten/rxjava-extras/issues/21, or mute the thread https://github.com/notifications/unsubscribe-auth/AATa6_hy99vpmYdpswgGJRuyoz_2Nh2Eks5rX6kjgaJpZM4LzM99 .

maslick commented 7 years ago

Why not !list.isEmpty() ? Or does it mean : put values into buffer when it is empty OR some condition. In this case you could put this check into your library, thus making user code less verbose?

davidmoten commented 7 years ago

If the list is empty return true which means add the item to the list

On Wed, 8 Feb 2017, 22:37 Pavel Maslov notifications@github.com wrote:

why not !list.isEmpty() ??

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/davidmoten/rxjava-extras/issues/21#issuecomment-278304381, or mute the thread https://github.com/notifications/unsubscribe-auth/AATa69hG6AvKn7hWeD_U_uELdqBtGj4Xks5raajagaJpZM4LzM99 .

maslick commented 7 years ago

why can't you handle this in your lib then?

davidmoten commented 7 years ago

ah sorry I see what you mean now. I don't want to put that check in the library because it is making a possibly incorrect assumption about what the user wants. For example the user might not want to add a certain emission (that fails some boolean check say) to the list if it is going to be the first element in the list. What you are talking about may be a common requirement but it is not something I should impose on everyone.

Happy to consider some usability suggestions though!

davidmoten commented 7 years ago

closing for lack of activity, feel free to reopen