Primitive Queue<any T> considerations

Dávid Karnok akarnokd at
Wed Nov 18 19:48:01 UTC 2015

Here is an example of a reactive service composition which involves
Integers as of now:

Observable<Integer> retrofitItemCount(int id) { ... }

Observable.range(0, 10)
.flatMap(v -> retrofitItemCount(v))
.reduce(0, (a, b) -> a + b)

This setup involves 12 queues that would require specifying default value:
- 1 queue that may hold the values from range 0..9 in flatMap
- 10 queues that may hold the number returned from the service call, again
in flatMap
- 1 queue that holds the sum until the Swing Event Dispatch loop can pick
it up in observeOn.

We are currently using null-sentinel objects which can be always
distinguished from regular values but this option goes away with value

The problem with user specified default value is that it leaks into every
level of a library.

My original problem, on one hand can be solved with implementation that
uses some extra data fields to indicate a cell is empty or occupied; I have
prototype implementations of such primitive queues right now. The problem
is that how will I be able to use them as the specialized implementation
when Queue<any T> is resolved for int, long, struct, etc.

2015-11-18 20:18 GMT+01:00 Richard Warburton <richard.warburton at>:

> Hi,
> I'm not sure about the default null-indicator because every time a queue
>> is needed in our library, that can serve a source with unique choice of a
>> default-null value. It is unlikely the users of the library want or can
>> specify that all the time.
> I appreciate that this is diverging directly form your language related
> question, but it is pertinent to writing anyfied collections using
> Valhalla. My experience using primitive specialised collections is that it
> has always been possible to have a sentinel value, though obviously my
> experience won't necessary reflect that of every single person in the Java
> community. It isn't always appropriate for it to be 0, which is what I
> think T.default is currently going to return for primitives and when I've
> done primitive specialised collections before they allow you to specify the
> missing value sentinel.
> Have you got of an actual genuine use case where a sentinel value doesn't
> work well, rather than a theoretical "hey, maybe you want to have a set
> that contains every possible int?"
> regards,
>   Richard Warburton
>   @RichardWarburto <>

Best regards,
David Karnok

More information about the valhalla-dev mailing list