Skip to content

Instantly share code, notes, and snippets.

View emmettna's full-sized avatar

Emmett Na emmettna

  • Ottawa
View GitHub Profile
config = load_config(“root”, “1234”, “localhost”)
final case class ConfigHost(value: String)
final case class ConfigId(value: String)
final case class ConfigPass(value: String)
def loadConfig(host: ConfigHost, id: ConfigId, pass: ConfigPass): Unit = ???
val configHost = ???
val configId = ???
val configPass = ???
loadConfig(
host = configHost,
id = configId,
pass = configPass)
val integerSample: Int = 123
val stringInteger: String = integerSample match {
case 123 => “123”
case _ => “”
}
Int integerSample = 123;
switch(integerSample){
case 123:
"123"
break;
default:
""
}
//I'm 🤔 if it compiles
final case class IntegerParser(value: Int)
val prasedInt = IntegerPraser(value = 1)
parsedInt match {
case IntegerParser(value) => value.toString
case _ => "Invalid Int"
}
val optionValue = Option(1)
optionValue match {
case Some(v) => ???
case None => ???
}
final case class DummyCaseClass(value: Int)
val dummyCaseClassOpt = Option(DummyCaseClass(1))
dummyCaseClassOpt match {
case Some(DummyCaseClass(v)) => v.toString
case Some(_) => ???
case None => ???
}
// equivalent
dummyCaseClassOpt match {
case v: Some[DummyCaseClass] => v.toString
val list: List[Option[Int]] = List(Some(1), None, Some(2))
val result: List[Int]=list.map( numberOpt => numberOpt match {
case Some(v) => v
case None => 0
})
"1,2,3".split(",").toList match {
case first :: second :: third :: Nil => "Counting Practice"
case _ => throw new Exception("This is not what I expected")
}