Stack Exchange
Scala collection that accepts pass-by-name parameters
Does such collection exist?
At the moment the code I have doesn't compile:
object pagerank {
    // TODO fixme
    val totalNodes: BigDecimal = 4

    class Node(in: => List[Node], out: => List[Node]) {
        def rank: BigDecimal = {
            in.foldLeft(BigDecimal(0))((sum, node) => sum + node.rank) + (1 / totalNodes / out.size)
        }
    }

    val d: Node = new Node(Nil, List(a, b, c))
    val b: Node = new Node(List(d), List(a, c))
    val c: Node = new Node(List(b, d), List(a))
    val a: Node = new Node(List(b, c, d), Nil)

  b.rank
}

Erros are:

forward reference extends over definition of value d
forward reference extends over definition of value c
forward reference extends over definition of value b
forward reference extends over definition of value a


Does making a,b,c,d lazy vals help?

Also, read What does a lazy val do? and What's the hidden cost of a lazy val?

Yes, adding "lazy" before a, b, c, d vals helped :)

Now all I have to do is finish the logic. Right now it's not right.

Glad to help. Good luck and have fun! (Feel free to post the solution yourself and accept it)
