How to extract path dependent types when wrapping graphs

11 views
Skip to first unread message

lucas....@nubank.com.br

unread,
Mar 24, 2020, 1:00:44 PM3/24/20
to scala-graph
Hi there!
My issue is that I'm working with an in-house method that generates a chart but returns it wrapped in a Try construct. I'm not able to call a .get right way, but, when I do this, I lose the direct path type dependency after running the find method on my graph - so, my return types becomes scalax.collection.Graph[myNodeType, scalax.collection.GraphEdge.DiEdge],#NodeT instead of myGraph.NoteT. With the first construct, I'm not able to call the method pathTo, which is what I need.

I've noticed the same thing happening if I happen to wrap my graph in a Traversable object, and then extracting it - I will lose the path dependency after extracting it using .head() or anything like that.

I explained my case more in more details in this question on Stack Overflow, hoping someone would come along, but that has not been the case so far.


My doubt, then, is: how to extract an inner node from a graph that has been extracted from some other construct, as a Try or a Traversable object, keeping the path type dependency in order to allow me to use that kind of method?

Peter Empen

unread,
Mar 25, 2020, 10:16:05 AM3/25/20
to scala...@googlegroups.com
Hi Lucas,

You cannot narrow down a type projection to a path dependent type other than calling asInstanceOf.
So try to stick with the path dependent type. In order to keep it, make the graph instance visible in your context. For instance, your Try should have the graph instance in scope and use the path dependent type.
You may achieve this by using a trait or by adding the graph to your arguments.

Your fallback is to work with the outer node and make a lookup prior to calling pathTo.

lucas....@nubank.com.br

unread,
Mar 25, 2020, 11:35:36 AM3/25/20
to scala-graph
Thank you for the clarification! Going to work with that.
Reply all
Reply to author
Forward
0 new messages