Skip to content

Instantly share code, notes, and snippets.

View patrickcousins's full-sized avatar

Patrick Cousins patrickcousins

View GitHub Profile
sealed class Yarn {
   class Cotton : Yarn()
   class Silk : Yarn()
   sealed class Wool : Yarn() {
       class Merino : Wool()
       class Alpaca : Wool()
   }
}
val yarn = when(spool) {
   is Yarn.Wool -> knit()
   is Yarn.Cotton -> knit()
}
class Merino : Yarn.Wool()
sealed class Yarn() {
   class Cotton : Yarn()
   class Wool : Yarn()
}
val done = when (result) {
   is Result.Success -> showList(result.items)
   is Result.Failure -> result.error.printStackTrace()
}
sealed class Result {
 class Success(val items: List<String>): Result()
 class Failure(val error: Throwable): Result()
 class Cancelled(): Result()
}
when (result) {
  is Result.Success -> showItems(result.items)
  is Result.Failure -> result.error.printStackTrace()
}
sealed class Result {
 class Success(val items: List<String>): Result()
 class Failure(val error: Throwable): Result()
}
<?php
class Bottles {
function verse($num_bottles):string {
if ($num_bottles == 2) {
return "2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.";
}