how I can create a type, that tpe contain String a...
# announcements
i
how I can create a type, that tpe contain String and Int?
k
You can't directly, either use
Any
or something like
Either<Int, String>
from #arrow.
i
this arrow means?
Either Int String is what I want, but I don't know how to do Left 3 or Right "3" in kotlin
does kotlin have value constructor?
k
A Pair<Int, String> with
42 to "string"
?
i
no
f :: Either Int String; f x = x; f (Left 3) will get Left 3, f (Right "S") will get Right "S"
the function f's parameter type can be Int or String wrapped by Either
it's about polymorphic, for example, f(x) if x is String, then make reverse x and return it, if x is Int, then plus one and return it
x's type can be Int or String
and we still can get 3 from (Left 3) by ff (Left x) = x
now how to do that in kotlin?
g
You can just use Sealed classes, same way as it done in #arrow library
k
@Ifvwm #arrow is just a library that has a class that handles what you want to do.