How to arrange return order in an idiomatic way using pattern matching in Scala -
def arrange(str1: string, str2: string): (string, string) = { if (str1 == "yellow") { return (str1, str2) } else { return (str2, str1) } }
i imagine write using pattern matching in more idiomatic way
def arrange(str1: string, str2: string) = str1 match { case "yellow" => str1 -> str2 case _ => str2 -> str1 }
Comments
Post a Comment