Created
January 29, 2021 21:32
-
-
Save LordRaydenMK/e8c154248e48dc77a475ca8afb59fc5c to your computer and use it in GitHub Desktop.
Cardinality of sum types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class NotificationSetting | |
object Disabled : NotificationSettings() // an object has one element -> cardinality = 1 | |
data class Enabled(val pushEnabled: Boolean, val emailEnabled: Boolean) : NotificationSettings() | |
// cardinality = cardinality (Disabled) + cardinality(Enabled) | |
// cardinality = 1 + (2 * 2) | |
// cardinality = 1 + 4 = 5 | |
sealed class Location | |
object Unknown : Location() | |
data class Somewhere(val lat: Float, val lng: Float) : Location() | |
// cardinality = cardinality (Unknown) + cardinality(Somewhere) | |
// cardinality = 1 + (∞ * ∞) | |
// cardinality = 1 + ∞ = ∞ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment