title: Scala code to check if parenthesis are balanced
body: <p>I'm writing a scala function to check for balanced parentheses. So <code>"()","([]{})"</code> are both balanced, but <code>")","(){[}]"</code> aren't balanced</p>
  
  <p>Below is the code I wrote which should be working. I have no idea why it say's false for all inputs I try.</p>
  
  <pre><code>package general
  
  import scala.collection.mutable.Stack
  import scala.collection.immutable.HashMap
  
  object BalanceParen {
      def main(args: Array[String]) {
          print(isBalanced("()"));
      }
      def isBalanced(input: String): Boolean = {
          val stack = new Stack[Char]
          val brace = HashMap('(' -&gt; ')', '[' -&gt; ']', '{' -&gt; '}')
  
          input map (( ch: Char ) =&gt; {
              if( brace contains ch ) stack push ch
              else {
                  if( brace.isEmpty )              return false
                  if( brace.get(stack.pop) != ch ) return false
              }
          })
          return stack.isEmpty
      }
  }
  </code></pre>