Advertisement
Da_Gamer

First attempt Pattern Matching

Oct 11th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.55 KB | None | 0 0
  1.  def bar(chars: List[Char]): List[(Char, Int)] = {
  2.     def foo(cFoo: Char, accFoo: List[(Char, Int)]): List[(Char, Int)] = accFoo match {
  3.       case Nil => (cFoo, 1) :: accFoo
  4.       case head :: tail => head match {
  5.         case (`cFoo`, y) => (cFoo, y + 1) :: tail
  6.         case (x, y) => (x, y) :: foo(cFoo, tail)
  7.       }
  8.     }
  9.     def blah(cBlah: List[Char], accBlah: List[(Char, Int)]): List[(Char, Int)] = cBlah match {
  10.       case Nil => accBlah
  11.       case head :: tail =>
  12.         blah(tail, foo(head, accBlah))
  13.     }
  14.     blah(chars, Nil)
  15.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement