Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Primarily working on www.AtomicKotlin.com

Bruce Eckel BruceEckel

💭
Primarily working on www.AtomicKotlin.com
View GitHub Profile
View kmonad.kts
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