jlleitschuh
07/03/2018, 3:46 PMRuckus
07/03/2018, 3:47 PMjlleitschuh
07/03/2018, 3:48 PMvalidateAndParse
without casting fromJson
to one specific type?jlleitschuh
07/03/2018, 3:49 PMintersection
type was what I needed.
https://stackoverflow.com/a/44453604/3708426jlleitschuh
07/03/2018, 7:19 PMRuckus
07/03/2018, 7:20 PMjlleitschuh
07/03/2018, 7:21 PMRuckus
07/03/2018, 7:22 PMA | B
) means it can be either A
or B
. Intersections (commonly represented as A & B
) means it has to be both A
and B
.jlleitschuh
07/03/2018, 7:22 PMRuckus
07/03/2018, 7:25 PMfun union(x: Int | String) { ... }
fun intersect(x: Int & String) { ... }
union(5) // OK
union("fred") // OK
intersect(5) // ERR: 5 !is String
intersect("fred") // ERR: "fred" !is Int
jlleitschuh
07/03/2018, 7:25 PMjlleitschuh
07/03/2018, 7:26 PMRuckus
07/03/2018, 7:26 PMjlleitschuh
07/03/2018, 7:26 PMRuckus
07/03/2018, 7:27 PMEither<A, B>
class (a common idiom in functional programming).jlleitschuh
07/03/2018, 7:27 PMEither
types.Ruckus
07/03/2018, 7:29 PMRuckus
07/03/2018, 7:29 PM