joinFrom(Iterable) optimization for empty Iterables

16 views
Skip to first unread message

Typhoon Storm

unread,
Jul 26, 2013, 12:33:40 AM7/26/13
to lam...@googlegroups.com
Hello, 

    Currently joinFrom(Iterable) does not work well with empty Iterables: it calls aggregateFrom(Iterable, Aggregator) and further calls aggregateFrom(iterable, discoverGenericType(iterable), aggregator); And discoverGenericType(iterable) cannot infer element class from empty Iterables, and we have to use joinFrom(Iterable, ElementClass) version instead.

    This means joinFrom(Iterable) can only work with Iterables that are assured to be non-empty. This is a strong predication! Most Iterables in practice cannot give this assurance.

    However, if Iterable is empty, then the result of join should just be empty string, and no need to detect its element class. So I think joinFrom(Iterable) should be checked against empty Iterables first, and if so, directly return the empty string as result. This also works other similar functions, such as aggregate, etc.

Reply all
Reply to author
Forward
0 new messages