Make one of
- Declare it explicitly as
Either[X, Y] . - Declare it as
MaybeResult[Y] (for type MaybeResult[A] = Either[Failure, A] )
Honestly, even then I declare this explicitly. The advantage # 2 (over your suggestion) is that with the standard Failure type (maybe Exception or List[String] ) you do not need to declare separate type aliases wherever you want to use this.
The advantage of using Either is that the user API is 100% clear . However, I would take another step and use Scalaz Validation :
def someApiCall : ValidationNEL[String, Result]
The advantage is that Validation can be arranged in ways that are not (otherwise they are isomorphic types). For instance:
def a(i : Int) : ValidationNEL[String, Float] def b(f : Float) : ValidationNEL[String, Boolean]
Then you can create:
a(1) >>= b
Same:
scala> def a(i : Int) : ValidationNEL[String, Float] = error("") a: (i: Int)scalaz.Scalaz.ValidationNEL[String,Float] scala> def b(f : Float) : ValidationNEL[String, Boolean] = error("") b: (f: Float)scalaz.Scalaz.ValidationNEL[String,Boolean] scala> lazy val c = a(1) >>= b c: scalaz.Validation[scalaz.NonEmptyList[String],Boolean] = <lazy>
source share