This file contains hidden or 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
| config = load_config(“root”, “1234”, “localhost”) |
This file contains hidden or 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
| 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 = ??? |
This file contains hidden or 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
| val configHost = ??? | |
| val configId = ??? | |
| val configPass = ??? | |
| loadConfig( | |
| host = configHost, | |
| id = configId, | |
| pass = configPass) |
This file contains hidden or 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
| val integerSample: Int = 123 | |
| val stringInteger: String = integerSample match { | |
| case 123 => “123” | |
| case _ => “” | |
| } |
This file contains hidden or 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
| Int integerSample = 123; | |
| switch(integerSample){ | |
| case 123: | |
| "123" | |
| break; | |
| default: | |
| "" | |
| } | |
| //I'm 🤔 if it compiles |
This file contains hidden or 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
| final case class IntegerParser(value: Int) | |
| val prasedInt = IntegerPraser(value = 1) | |
| parsedInt match { | |
| case IntegerParser(value) => value.toString | |
| case _ => "Invalid Int" | |
| } |
This file contains hidden or 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
| val optionValue = Option(1) | |
| optionValue match { | |
| case Some(v) => ??? | |
| case None => ??? | |
| } |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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 | |
| }) |
This file contains hidden or 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
| "1,2,3".split(",").toList match { | |
| case first :: second :: third :: Nil => "Counting Practice" | |
| case _ => throw new Exception("This is not what I expected") | |
| } |