Created
September 12, 2019 11:02
-
-
Save francescofrontera/a0a2d80cc4516276db851de58a389c9d to your computer and use it in GitHub Desktop.
Free, Simple PhantomBuilder in scala
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
object PhantomBuilder extends App { | |
object Builder { | |
sealed trait State | |
trait Checked extends State | |
trait Unchecked extends State | |
case class Tuple2StringBuilder[_1CHECK, _2CHECK](_1: Option[String], | |
_2: Option[String]) { | |
def _01Set(str: String) = this.copy[Checked, _2CHECK](_1 = Some(str)) | |
def _02Set(str: String) = this.copy[_1CHECK, Checked](_2 = Some(str)) | |
} | |
implicit class BuildOps(builder: Tuple2StringBuilder[Checked, Checked]) { | |
def build = (builder._1.get, builder._2.get) | |
} | |
def tuple: Tuple2StringBuilder[Unchecked, Unchecked] = | |
new Tuple2StringBuilder[Unchecked, Unchecked](None, None) | |
} | |
val tuple = Builder.tuple | |
._01Set("Marco") | |
._02Set("Tagliabosco") | |
.build | |
print(tuple) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment