Skip to content

Instantly share code, notes, and snippets.

@itang
Created April 10, 2021 23:59
Show Gist options
  • Save itang/1f4aaa259bdc8670056669e35d41ecfb to your computer and use it in GitHub Desktop.
Save itang/1f4aaa259bdc8670056669e35d41ecfb to your computer and use it in GitHub Desktop.
extension[T] (t: T)
infix inline def |>[B](block: T => B): B = block(t)
infix inline def <|(block: T => Unit): T =
block(t)
t
enum Opt[+T]:
case Empty
case Box(t: T)
def getOrElse[B >: T](b: => B): B = this match
case Empty => b
case Box(t) => t
infix def ||[B >: T](b: => B): B = getOrElse(b)
@main
def main(): Unit =
val a = Opt.Empty
(a || 4000)
<| println
|> (_ + 10000)
|> println
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment