2

I have been trying the Bloxorz assignment as part of the Functional Program Design in Scala course and have been trying to add an element to a Stream as below but I am getting:

Cannot resolve symbol #::.

There is some very small, obvious mistake in this code. What am I doing wrong here?

def neighborsWithHistory(b: Block, history: List[Move]): Stream[(Block, List[Move])] = {
  (b.neighbors foldLeft Stream((b, history))) {
    case (acc, (bl, move)) => acc #:: (bl, move :: history)
  }
}
Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321
Aditya Singh
  • 15,810
  • 15
  • 45
  • 67

1 Answers1

2

Methods ending with a colon are right associative. Since #:: is defined as a ConsWrapper on a Stream, your acc needs to be on the right hand side:

(bl, move :: history) #:: acc
Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321