Hey guys, is it okay to use arrow-meta's unionType...
# arrow-meta
b
Hey guys, is it okay to use arrow-meta's unionTypes? It's not very documented and I can't find examples online. What's the best way to consume then?
šŸ‘€ 1
r
Hi Benoit, they have been removed from
main
as this is something the lang may get in an untagged version and the way we had to make it work as a plugin is not optimal. To implement this in a good way we’d need access to parts of compiler services that are currently not exposed to plugins like the TypeChecker. We are currently focusing in type refinements and improving the Proofs plugin to be focused on compile time DI but w are not really gonna attempt union types are the moment. The IDE resolution part is not possible without an IDEA plugin at the moment and we are waiting for FIR and a stable phased compiler plugin api to take on more ambitious projects like unions and other type system related features.
b
That's kind of what I was expecting, hopefully union types become a native thing in the not too distant future, to me that's the one thing Kotlin needs to become a truly functional language. Thank you for your answer Raul!
r
no problem and very much wanting union types in kotlin too.
j
i've had good luck typealiasing an interface Pair (which is just a class in Koltin proper) and using type dispatch for lock and key delegates of specific parameters like Twin tuples, pairs as vectors, vectors of pairs, linked lists of Pairs etc. the effect is a union. intellij renders typealiases in a hideous way but for composable types that's a workaround i have capitalized on
b
I am achieving union types by wrapping types in a sealed class like so :
Copy code
sealed class MyUnion {
    class StringW(val value: String) : MyUnion()
    class IntW(val value: Int) : MyUnion()
}
But this gets very verbose very quickly
j
you can write the union as a ByteBuffer envelope/letter if you are extremely determined, since this will let you perform C code (minus unsigned types) right on your custom struct-vtable contents. clearly you have a job of flyweight mementos with that approach in the JVM languages
b
The main point of using union types is exhaustiveness on
when
statements, which you would lose with such an approach