Last active
March 25, 2018 00:05
-
-
Save themathmagician/bfead55319bda565090de259999cd7d8 to your computer and use it in GitHub Desktop.
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
// Map a list to a frequency list by using groupBy with identity and mapValues | |
val chars = "Peace and harmony" | |
chars.groupBy(identity).mapValues(_.size).toList | |
//Use a tupple: type to pass in two arguments for pattern matching, like goldilocks("porridge", "Mama") | |
def goldilocks(tuple: (String, String)) = tuple match { | |
case ("porridge", "Papa") ⇒ "Papa eating porridge" | |
case ("porridge", "Mama") ⇒ "Mama eating porridge" | |
case ("porridge", "Baby") ⇒ "Baby eating porridge" | |
case _ ⇒ "what?" | |
} //> goldilocks: (tuple: (String, String))String | |
assert(goldilocks("porridge", "Mama") == "Mama eating porridge") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment