Skip to content

Single.zip with empty Iterable should not throw NoSuchElementException #6916

Closed
@valeriyo

Description

@valeriyo

RxJava 2.2.17

The following method:

public static <T, R> Single<R> zip(final Iterable<? extends SingleSource<? extends T>> sources, Function<? super Object[], ? extends R> zipper)

throws NoSuchElementException if the Iterable sources is empty. This is very unfortunate, and it goes against functional programming principles.

The zipper function should be invoked with an empty array - and if zipper can handle empty Iterable - it will produce a value R. If zipper cannot handle an empty array - it's up to zipper to throw an exception. Basically, RxJava shouldn't put artificial constraints on the Iterable.

In my specific case, the zipper function is Kotlin's Iterable<T>.all(predicate: (T) -> Boolean) - which falls back to true if Iterable is empty - and that's what I want to receive - a Single of true.

Thanks.

#3789 was a wrong "fix" for the #3784 issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions