This file contains hidden or 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 Bag<out THING> { | |
object Empty: Bag<Nothing>() | |
data class NonEmpty<out THING>(val thing: THING): Bag<THING>() | |
// Make a Bag with a THUNG in it | |
companion object { | |
fun <THUNG> make(thung: THUNG): Bag<THUNG> = NonEmpty(thung) | |
} | |
// Do stuff to the THING in the Bag by providing a thingToBagOfThang |