Skip to main content
Code Review

Return to Answer

A rightleft-fold is an elegant solution too:

class Node (children:List[Node], value:Int) {
 def totalCost : Int = (value /: children) (_ + _.totalCost)
}

A right-fold is an elegant solution too:

class Node (children:List[Node], value:Int) {
 def totalCost : Int = (value /: children) (_ + _.totalCost)
}

A left-fold is an elegant solution too:

class Node (children:List[Node], value:Int) {
 def totalCost : Int = (value /: children) (_ + _.totalCost)
}
Source Link

A right-fold is an elegant solution too:

class Node (children:List[Node], value:Int) {
 def totalCost : Int = (value /: children) (_ + _.totalCost)
}
lang-scala

AltStyle によって変換されたページ (->オリジナル) /