Iterate manually inside TraversableOnce

37 views
Skip to first unread message

Fernando Pelliccioni

unread,
Dec 13, 2016, 9:05:46 AM12/13/16
to scala-i...@googlegroups.com
Hello!

I am new to the forum and to Scala. 
Excuse me in advance if I ask an obvious question.

I was looking at the following code: 


  def reduceLeft[B >: A](op: (B, A) => B): B = {
    if (isEmpty)
      throw new UnsupportedOperationException("empty.reduceLeft")

    var first = true
    var acc: B = 0.asInstanceOf[B]

    for (x <- self) {
      if (first) {
        acc = x
        first = false
      }
      else acc = op(acc, x)
    }
    acc
  }

And I was wondering if it is possible to iterate manually, using next() and hasNext (instead of using for( <-)), in the context of TraversableOnce.

Thanks and regards,
Fernando Pelliccioni.

Sébastien Doeraene

unread,
Dec 13, 2016, 9:12:24 AM12/13/16
to scala-internals
Hello,

Looks like a question for scala-user (https://groups.google.com/forum/#!forum/scala-user) instead.

Cheers,
Sébastien

--
You received this message because you are subscribed to the Google Groups "scala-internals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-internals+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Fernando Pelliccioni

unread,
Dec 13, 2016, 9:15:00 AM12/13/16
to scala-i...@googlegroups.com
Oh Sorry!
Thanks!
Reply all
Reply to author
Forward
0 new messages