Philipp Mayer
01/21/2021, 9:26 PMflowNodes.forEach { initialNode ->
initialNode.succeedingNodes.list().forEach { nextNode ->
graph.addArc(initialNode to nextNode)
}
}
in a more fluent way? Seems like I'm missing something.
The use case would be the following:
I have an initial Node 1 with the succeeding nodes 2 and 3.
The target is to add 1 to 2 and 1 to 3 to the graph.
thanks a lot!Javier
01/21/2021, 9:38 PMJavier
01/21/2021, 9:39 PMJavier
01/21/2021, 9:41 PMPhilipp Mayer
01/22/2021, 8:21 AMpablisco
01/22/2021, 9:28 AMflowNodes.flatMap { initialNode ->
initialNode.succeedingNodes.list()
.map { initialNode to it }
}.forEach(graph::addArc)
I’m assuming that glowNodes is a list.
It’s basically the same but allows to have two separate operations which means you can move things around more easily. If everything here under your control? Would be good to see more of the codepablisco
01/22/2021, 9:32 AMprivate fun Node.succeedinPairs() =
succeedingNodes.list().map { this to it }
// then
flowNodes.flatMap(Node::succeedinPairs)
.onEach(graph::addArc)
Always good to split things into smaller (and easier to understand) parts 🙂Philipp Mayer
01/22/2021, 2:23 PMPhilipp Mayer
01/22/2021, 2:24 PMpablisco
01/22/2021, 3:00 PM