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
val Pattern = "([a-cA-C])".r | |
def matchExample(x: AnyVal): Unit = { | |
x match { | |
case i: Int => "Matching on type" | |
case 1 => "Matching on a literal" | |
case 2 | 3 => "Matching on multiple literals" | |
case x if 0 until 10 contains x => "Matching with guard" | |
case ab@(a, b) => "Matching and destructuring a tuple, but keeping the original tuple bound to ab" | |
case x::xs => "Matching and destructuring a list" |
It may come as a surprise to many but Scala actually supports a flexible form Uniform Function Call Syntax (sometimes also referred to as Uniform Calling Syntax or Universal Function Call Syntax), henceforth referred to as UFCS. This feature can be seen in D, Rust and Nim. An example in Nim:
proc add(a: int, b: int): int =
a + b
add(1, 2)
# OR
1.add(2)
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
implicit val x: String = "up here" | |
def implicitString(implicit x: String) = x | |
// println(implicitString) | |
/////////////////////////////////////////////////////////////////////////////// | |
implicit val booleanInstance: Boolean = true | |
implicit val intInstance: Int = 5 |
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
import io.circe.JsonObject | |
object BaseExError { | |
def generateErrorId(): String = UUID.randomUUID().toString.take(8) | |
def errorDataFromJsonObj(jsonObj: JsonObject): Map[String, String] = | |
jsonObj.toMap.mapValues(_.noSpaces) | |
/** |
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
cocktail_ingredients = { | |
"Alexander": ["3 cl cognac", "3 cl brown crème de cacao", "3 cl light cream"], | |
"Americano": ["3 cl Campari", "3 cl red vermouth", "A splash of soda water"], | |
"Angel Face": ["3 cl gin", "3 cl Apricot brandy", "3 cl Calvados"], | |
"Aviation": [ | |
"45 ml gin", | |
"15 ml lemon juice", | |
"15 ml maraschino liqueur", | |
"1 barspoon crème de violette", | |
], |
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
('gin', 18) | |
('fresh lemon juice', 12) | |
('simple syrup', 12) | |
('fresh lime juice', 11) | |
('lemon juice', 9) | |
('cognac', 8) | |
('angostura bitters', 8) | |
('vodka', 8) | |
('white rum', 7) | |
('triple sec', 6) |
OlderNewer