Skip to content

Instantly share code, notes, and snippets.

View johnhungerford's full-sized avatar

johnhungerford

  • Two Six Labs
  • Mt. Laurel Township, NJ
View GitHub Profile
@johnhungerford
johnhungerford / getEither.scala
Last active March 27, 2024 12:08
Kotlin/TypeScript -like syntax for accessing nested optional types
//> using scala 3.3
import scala.util.{Failure, NotGiven, Success, Try, boundary}
import boundary.{Label, break}
import scala.annotation.targetName
/**
* Proof of concept implementation of a syntax similar to Kotlin and
* typescript. Within the context provided by [[getEither]], you can call
* `?` on any optional/failable type (currently supports [[Option]],
@johnhungerford
johnhungerford / ZeroOverHeadOption.scala
Last active November 10, 2023 18:35
Zero overhead Option in Scala 3
//> using scala 3.3.0
import scala.util.{Try, Success, Failure}
import scala.reflect.Typeable
import scala.util.NotGiven
import scala.annotation.implicitNotFound
type Opt[T] = Opt.Opt[T]
object Opt:
@johnhungerford
johnhungerford / TicTacToe.Scala
Last active March 26, 2023 11:13
Type level tic tac toe using match types
sealed trait Bool
object Bool:
sealed trait True extends Bool
sealed trait False extends Bool
sealed trait Nat
object Nat:
sealed trait _0 extends Nat
sealed trait Succ[N <: Nat] extends Nat