We have considered generics based unions but the current union
implementation in Elemental2 is much more practical for the Elemental API
needs since most of the time the consumption of the union is not based on a
shared abstraction but based on specific type guarded with type check. Here
is the Julien's pro/con summary from the design doc:

Advantage of generics based union:
  - Can be shared across different compilation unit.

Disadvantage:
  - The number of types involved in an union type is potentially infinite.
We will need several interfaces for covering the majority of use case of
union type.
  - need specific treatment by J2CL to emit the correct closure annotation
  - not really user friendly because we cannot implement isXyz test methods

Technically we can also add a helper to our union that takes a consumer
function similar to the article. That will give you the same benefit (i.e.
perform operations on the union based on the intersection in a type-safe
way). However I think that's rarely useful in Elemental case. If you think
it will be helpful, feel free to open feature request in elemental2 github
issue tracker with examples of the APIs that will benefit from this.

On Wed, Sep 12, 2018 at 2:20 PM Hristo Stoyanov <hr.stoya...@gmail.com>
wrote:

> I wonder if the hack described below can be applied to Elemental2 union
> types:
>
>
> https://blog.jooq.org/2016/02/16/an-ingenious-workaround-to-emulate-sum-types-in-java/
>
> --
> You received this message because you are subscribed to the Google Groups
> "GWT Contributors" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-web-toolkit-contributors/fe6e7cc4-16fe-4975-8087-fc07ba1bc5a8%40googlegroups.com
> <https://groups.google.com/d/msgid/google-web-toolkit-contributors/fe6e7cc4-16fe-4975-8087-fc07ba1bc5a8%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAN%3DyUA0HOabe_q07-oQAyx6ov7ezmq%2BQMdC5VXHcFf1qS83BHw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to