-
Notifications
You must be signed in to change notification settings - Fork 3.1k
add Either.left and Either.right typed as Either #6328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
LGTM in a general way, but I haven't worked in a codebase that makes especially heavy use of |
|
what's the value over just doing simple type ascription? e.g. |
|
the value is that |
|
@tpolecat points out that:
have you considered ways of avoiding that...? |
|
the only way I know is already mentioned in gitter, like implicit class LeftOps[A](a: A) extends AnyVal { def left[B]: Either[A,B] = Left[A,B](a) }but I share your concern on selling it, though that would be awesome i think ) |
|
To get a precise type with something like this (where object Either {
def left[A]: FromLeftPartiallyApplied[A] =
new FromLeftPartiallyApplied[A]
def right[A]: FromRightPartiallyApplied[A] =
new FromRightPartiallyApplied[A]
}
class FromLeftPartiallyApplied[A](val dummy: Boolean = true)
extends AnyVal {
def apply[B](b: B): Either[B, A] = Left(b)
}
class FromRightPartiallyApplied[A](val dummy: Boolean = true)
extends AnyVal {
def apply[B](b: B): Either [A, B] = Right(b)
}This means we can now use it like this: This technique is described here: https://typelevel.org/cats/guidelines.html#partially-applied-type-params |
|
closing this one since no one has objected to #6329 |
motivation:
LeftandRightconstructors are typed asLeftandRightrespectively, but sometimes we want something likeOption.emptywhich returnsNonebut typed asOption.The test represents a code that would not compile if plain
Left/Rightconstructors are used@SethTisue please take a look