| final case class NodeA(id: Int, op: Function1[Int, Int]) extends AST |
sealed trait AST extends Product with Serializable
However, If I try to do something like: ```scala def procNode(node: g.NodeT):Unit = node.id + 1 ``` I'm getting compile error, since node is of type `g.NodeT`. How do I implement `procNode` correctly ? Thank you! |
|||||
sealed trait AST {
def id: Int
}
root.innerNodeTraverser foreach procNode
--
You received this message because you are subscribed to the Google Groups "scala-graph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-graph...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-graph/aae77de1-1a7b-4028-92cf-b4fa90773919%40googlegroups.com.
sealed trait AST
final case class NodeA(id: Int, op: Function1[Int, Int]) extends AST {
def run(): Unit = println(">>>>> Run A")
}
final case class NodeB(id: Int, op: Function1[Int, Int]) extends AST {
def run(): Unit = println(">>>>> Run B")
}
// Traverse graph nodes
def procNode(node: g.NodeT): Unit = node.value match {
case n: NodeA => n.run()
case n: NodeB => n.run()
case _ =>
}
root.innerNodeTraverser.foreach(procNode)
If you don't want NodeT, why not do an *outer* traversal instead? Or, for that matter, just calling ".outer" on the node before passing it to procNode?--Daniel C. Sobral
On Wed, Apr 15, 2020 at 5:50 AM tampler <socne...@gmail.com> wrote:
--HelloI wanna traverse an AST-based graph and call some method for each node. I made some impl, but can't call the node method, since I"m getting `NodeT` in return.```scala
final case class NodeB(id: Int, op: Function1[Int, Int]) extends AST
final case class NodeA(id: Int, op: Function1[Int, Int]) extends AST
sealed trait AST extends Product with Serializable
```
val g = Graph.from(nodes, edges)
val root = g.get(n0)
// Traverse graph
def procNode(node: g.NodeT): Unit = println(node) root.innerEdgeTraverser.map(_.foreach(procNode))
However, If I try to do something like:
```scala
def procNode(node: g.NodeT):Unit = node.id + 1
```
I'm getting compile error, since node is of type `g.NodeT`. How do I implement `procNode` correctly ?
Thank you!
You received this message because you are subscribed to the Google Groups "scala-graph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala...@googlegroups.com.