Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 15th, 2012  |  syntax: None  |  size: 0.33 KB  |  hits: 5  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. def reduceLeft[B >: A](op: (B, A) => B): B = {
  2.     if (isEmpty)
  3.       throw new UnsupportedOperationException("empty.reduceLeft")
  4.    
  5.     var first = true
  6.     var acc: B = 0.asInstanceOf[B]
  7.  
  8.     for (x <- self) {
  9.       if (first) {
  10.         acc = x
  11.         first = false
  12.       }
  13.       else acc = op(acc, x)
  14.     }
  15.     acc
  16.   }