either

ox.either
object either

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
either.type

Members list

Value members

Concrete methods

inline def apply[E, A](inline body: (Label[Either[E, A]]) ?=> A)(using nn: NotGiven[Label[Either[Nothing, Nothing]]]): Either[E, A]

Within an either block, allows unwrapping Either and Option values using ok. The result is the right-value of an Either, or the defined-value of the Option. In case a failure is encountered (a left-value of an Either, or a None), the computation is short-circuited and the failure becomes the result. Failures can also be reported using fail.

Within an either block, allows unwrapping Either and Option values using ok. The result is the right-value of an Either, or the defined-value of the Option. In case a failure is encountered (a left-value of an Either, or a None), the computation is short-circuited and the failure becomes the result. Failures can also be reported using fail.

Uses the boundary-break mechanism.

Type parameters

A

The success type.

E

The error type.

Value parameters

body

The code block, within which Eithers and Options can be unwrapped using ok. Failures can be reported using fail. Both ok and fail are extension methods.

Attributes

Returns

The result - either an error, or success - represented as an Either. The error type can be set to the union of all error types that are used. In case of options, failure type is assumed to be Unit.

Example
 val v1: Either[Int, String] = ???
 val v2: Either[Long, String] = ???
 val result: Either[Int | Long, String] =
   either:
     v1.ok() ++ v2.ok()
inline def catching[T](inline t: (Label[Either[Throwable, T]]) ?=> T): Either[Throwable, T]

Catches non-fatal exceptions that occur when evaluating t and returns them as the left side of the returned Either.

Catches non-fatal exceptions that occur when evaluating t and returns them as the left side of the returned Either.

Attributes

Extensions

Extensions

extension [E](e: E)
transparent inline def fail(): Nothing
extension [E, A](inline f: Fork[Either[E, A]])
transparent inline def ok(): A

Join the fork and unwrap the value of its Either result, short-circuiting the computation to the enclosing either, in case this is a left-value.

Join the fork and unwrap the value of its Either result, short-circuiting the computation to the enclosing either, in case this is a left-value.

If the fork fails with an exception, the enclosing scope ends (when the fork was started with fork). Exceptions are re-thrown by this method only when the fork is started using forkUnsupervised or forkCancellable.

Attributes

extension [E, A](inline t: Either[E, A])
transparent inline def ok(): A

Unwrap the value of the Either, short-circuiting the computation to the enclosing either, in case this is a left-value.

Unwrap the value of the Either, short-circuiting the computation to the enclosing either, in case this is a left-value.

Attributes

extension [E, A](inline t: Right[E, A])
transparent inline def ok(): A

Unwrap the value of the Either, returning value of type A on guaranteed Right case.

Unwrap the value of the Either, returning value of type A on guaranteed Right case.

Attributes

extension [E, A](inline t: Left[E, A])
transparent inline def ok(): A

Unwrap the value of the Either, short-circuiting the computation to the enclosing either.

Unwrap the value of the Either, short-circuiting the computation to the enclosing either.

Attributes

extension [A](inline t: Option[A])
transparent inline def ok(): A

Unwrap the value of the Option, short-circuiting the computation to the enclosing either, in case this is a None.

Unwrap the value of the Option, short-circuiting the computation to the enclosing either, in case this is a None.

Attributes

extension [A](inline t: Some[A])
transparent inline def ok(): A

Unwrap the value of the Option, returning value of type A on guaranteed Some case.

Unwrap the value of the Option, returning value of type A on guaranteed Some case.

Attributes

extension [A](inline t: None.type)
transparent inline def ok(): A

Unwrap the value of the Option, short-circuiting the computation to the enclosing either on guaranteed None.

Unwrap the value of the Option, short-circuiting the computation to the enclosing either on guaranteed None.

Attributes