I have two methods that are used to create Currency enums from Strings. The enum Currency is a Java enum.
Their signatures are:
def sCurrency: Option[Currency] Or One[ErrorMessage] = ???
def cCurrency: Currency Or One[ErrorMessage] = ???
Try as I might I can't seem to get the Try / Recover with and type parameters correct for all situations. I've hacked implementations together to only handle the Good -
def cCurrency: Currency Or One[ErrorMessage] =
Good(String2Currency(currencyString))
def sCurrency: Option[Currency] Or One[ErrorMessage] =
Good(currencyString map (String2Currency(_)))
implicit def String2Currency(v: String): Currency = Currency.valueOf(v.toUpperCase)
I struggled to find an article that covers the complexity of mixing Try, One, Options, Or and recoverWith, so my question is twofold - How should I implement these methods, and can anyone explain / link an article on what is actually going here and how it works?
I can't change the return types of either method.