is there still a way I could rewrite the function to a function which pattern matches its argument? One pattern for
Station
and one case forOption[Station]
?
Someone smarter than I am might have a creative solution using Scala’s type system; my only thought here is that if you are set on having a different implementation for an Option vs a concrete instance, you could potentially write each as a PartialFunction, and use orElse to chain them together.
I’m rather partial (no pun intended) to just sticking with a single parameter type in order to simplify things.
In your example, one function is just unwrapping the Option, which seems unnecessary - maybe you could just do something like:
val startingStation = freeVertices.headOption
val routings = startingStation.map(station => firstRoutings(station)) getOrElse Nil
Then, you could just discard the function that takes the Option.