Finding a more elegant solution
I have this piece of code, I just use it in test cases where there is no need to handle errors. What does he do:
- enter a list of lines
- Analyze them using the DSJSonmapper.parseDSResult method.
- filters them and extracts the Right value from each of them (on the left is an exception)
The code is as follows:
def parseDs(ins: List[String]) = { def filterResults[U, T](in: List[Either[U, T]]): List[T] = { in.filter(y => y.isRight).map(z => z.right.get) } filterResults(ins.map(x => DSJsonMapper.parseDSResult(x))) }
Now I have not done many polymorphic functions, but it works. However, it seems to me that this is a little ugly. Has anyone got the best offer on how to do the same.
I know that this will come down in case of personal preference. But suggestions are welcome.
Bryan hunt
source share