Anton Kuzmin
Anton Kuzmin

Reputation: 831

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:

Upvotes: 0

Views: 80

Answers (0)

Related Questions