Created
April 10, 2021 23:59
-
-
Save itang/1f4aaa259bdc8670056669e35d41ecfb to your computer and use it in GitHub Desktop.
This file contains 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
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