Advertisement
valtih1978

Custom lookupis more concise than find and match Some

Jun 26th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.42 KB | None | 0 0
  1. //custom lookup
  2. def codeBits(table: CodeTable)(char: Char): List[Bit] = table match {
  3.     case x :: xs => if (x. _1 == char) x._2 else codeBits(xs)(char)
  4.   }
  5.  
  6. // using standard find and match Some options
  7. def codeBits(table: CodeTable)(char: Char): List[Bit] = {
  8.     val couple = table.find({case (c, _) => c == char})
  9.     couple match { case Some((_ , bits)) => bits }
  10.   }                                               /
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement