Search code examples
scalascala-streams

Cannot resolve symbol #:: error for streams in Scala


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)
  }
}

Solution

  • 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