pakoito
04/19/2019, 4:34 PMlouiscad
04/19/2019, 5:49 PMpakoito
04/19/2019, 7:24 PMlouiscad
04/19/2019, 7:49 PMinstanceof nor is check here. Reference equality and unchecked casts are used, and these are way cheaper than any complicated Option type you can come up with and nesting it.pakoito
04/19/2019, 7:56 PMthere’s any big performance tradeoffs there at allI thought you meant compared to sealed classes, which depending on implementation may be a direct call into one of the branches instead of doing the ifcheck
pakoito
04/19/2019, 7:58 PMsealed class Tristate<A> {
fun <B> fold(fu: () -> B, fn: () -> B, fa: (A) -> B)
object Uninitialized: Tristate<Nothing> {
override fun <B> fold(fu: () -> B, fn: () -> B, fa: (A) -> B) = fu()
}
object Nullish: Tristate<Nothing> {
override fun <B> fold(fu: () -> B, fn: () -> B, fa: (A) -> B) = fn()
}
data class Option<A>(val a: A): Tristate<A> {
override fun <B> fold(fu: () -> B, fn: () -> B, fa: (A) -> B) = fa(a)
}
}pakoito
04/19/2019, 7:59 PMpakoito
04/19/2019, 8:01 PMpakoito
04/19/2019, 8:03 PMObject like in a dynamic languagepakoito
04/19/2019, 8:05 PMlouiscad
04/19/2019, 8:50 PMlazy FYI.pakoito
04/19/2019, 8:56 PMComparing a reference check to JavaScript is a bit excessive IMO.Not reference check, going down to
Any? to store a value on a variable so the variable can contain an arbitrary value of an unrelated type. So, dynamic typing of variables 😄pakoito
04/19/2019, 8:57 PMlouiscad
04/19/2019, 9:02 PMVsevolod Tolstopyatov [JB]
04/20/2019, 2:19 PMVirtual dispatch is not an issue here. But allocations ofvirtual dispatchinstaceof
Option on each value and lambdas for fold are.
One could think of Result-like inline class, but then boxing kicks in 😞Dico
04/21/2019, 1:05 AM