Result

steps.result.Result
See theResult companion enum
object Result

Attributes

Companion
enum
Graph
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
Result.type

Members list

Grouped members

Constructing Results through evaluating

inline def apply[T, E](inline body: (Label[Result[T, E]]) ?=> T): Result[T, E]

Evaluates body, returning the output as an Ok value.

Evaluates body, returning the output as an Ok value.

Within body:

  • eval.ok can be used to unwrap Result values, with the body short-circuiting back with the error.
  • eval.raise can be used to quickly short-circuit with an error.

Attributes

object eval

Operations that are valid under a Result.apply scope.

Operations that are valid under a Result.apply scope.

Attributes

See also
Supertypes
class Object
trait Matchable
class Any
Self type
eval.type

Constructing Results through other means

def catchException[T, E](catcher: PartialFunction[Throwable, E])(body: => T): Result[T, E]

Evaluates body, catching exceptions accepted by catcher as errors.

Evaluates body, catching exceptions accepted by catcher as errors.

Attributes

See also

Try.apply for a similar method returning scala.util.Try, but works on all NonFatal exceptions.

val empty: Result[EmptyTuple, Nothing]

Right unit for chains of cons. An Ok with an EmptyTuple value.

Right unit for chains of cons. An Ok with an EmptyTuple value.

Attributes

Extensions: value accessors and disambiguators

def exists(pred: T => Boolean): Boolean

Returns true if result contains an Ok value that satisfies pred.

Returns true if result contains an Ok value that satisfies pred.

Attributes

def forall(pred: T => Boolean): Boolean

Returns true if result contains an Ok value that satisfies pred.

Returns true if result contains an Ok value that satisfies pred.

Attributes

def get: T

Returns the Ok value from the result, and throws an exception if it is an error.

Returns the Ok value from the result, and throws an exception if it is an error.

Attributes

Throws
ResultIsErrException

if the result is an Err.

def getErr: E

Returns the error from the result, and throws an exception if it is an Ok value.

Returns the error from the result, and throws an exception if it is an Ok value.

Attributes

Throws
java.util.NoSuchElementException

if the result is an Ok.

def getNullable: T | Null

Unwraps the inner value, returing null if there is an error.

Unwraps the inner value, returing null if there is an error.

Attributes

def getOrElse(default: => T): T

Returns the Ok value from the result, or default if the result is an Error.

Returns the Ok value from the result, or default if the result is an Error.

Attributes

def isErr: Boolean

Returns whether the result is Err.

Returns whether the result is Err.

Attributes

def isOk: Boolean

Returns whether the result is Ok.

Returns whether the result is Ok.

Attributes

def tap(peek: T => Unit): r.type

Runs peek with the wrapped Ok value, if it exists.

Runs peek with the wrapped Ok value, if it exists.

Attributes

def tapErr(peek: E => Unit): r.type

Runs peek with the wrapped Err error, if it exists.

Runs peek with the wrapped Err error, if it exists.

Attributes

Extensions: transformers to different types under the result

def flatMap[U](f: T => Result[U, E]): Result[U, E]

Returns the output of f from applying it to the Ok value, otherwise keeping the Err case.

Returns the output of f from applying it to the Ok value, otherwise keeping the Err case.

Attributes

def flatten: Result[T, E]

Flattens a nested Result with the same error type.

Flattens a nested Result with the same error type.

Attributes

def handleErr[E1](f: E => Result[T, E1]): Result[T, E1]

Returns the output of f from applying it to the Err case error, otherwise keeping the Ok case. Similar to flatMap, but on the Err case.

Returns the output of f from applying it to the Err case error, otherwise keeping the Ok case. Similar to flatMap, but on the Err case.

Attributes

def map[U](f: T => U): Result[U, E]

Maps the Ok value through f, otherwise keeping the Err error.

Maps the Ok value through f, otherwise keeping the Err error.

Attributes

def mapErr[E1](f: E => E1): Result[T, E1]

Maps the Err error through f, otherwise keeping the Ok value.

Maps the Err error through f, otherwise keeping the Ok value.

Attributes

Extensions: combining multiple results into a new one

def and[U, E1](other: => Result[U, E1]): Result[(T, U), E | E1]

Returns a tuple of r and other if both are Ok, or the first error otherwise. Short-circuits, so other is not evaluated if r is an Err.

Returns a tuple of r and other if both are Ok, or the first error otherwise. Short-circuits, so other is not evaluated if r is an Err.

Attributes

def andTrace[U, E1](other: => Result[U, E1]): Result[(T, U), Either[E, E1]]

Returns a tuple of r and other if both are Ok, or the first error otherwise. Short-circuits, so other is not evaluated if r is an Err.

Returns a tuple of r and other if both are Ok, or the first error otherwise. Short-circuits, so other is not evaluated if r is an Err.

Unlike and, returns the error disambiguated by Either: Left if r is an Err, and Right if r is Ok but other is not.

Attributes

infix def cons[Ts <: Tuple](other: Result[Ts, List[E]]): Result[T *: Ts, List[E]]

Generalized version of zip to work with arbitrary tuples.

Generalized version of zip to work with arbitrary tuples.

Attributes

See also

zip

def or[E1](other: => Result[T, E1]): Result[T, E1]

Returns r if it is Ok, otherwise evaluates and returns other.

Returns r if it is Ok, otherwise evaluates and returns other.

Attributes

def zip[U](other: Result[U, E]): Result[(T, U), List[E]]

Returns a tuple of r and other if both are Ok, other return all errors as a List. Does '''not''' short-circuit.

Returns a tuple of r and other if both are Ok, other return all errors as a List. Does '''not''' short-circuit.

Attributes

Extensions: conversions into other types

def errOption: Option[E]

Returns the Err error from the result.

Returns the Err error from the result.

Attributes

def toEither: Either[E, T]

Conversionerts the result into an Either.

Conversionerts the result into an Either.

Attributes

def toOption: Option[T]

Converts the result into an Option, with Some case if the value is Ok.

Converts the result into an Option, with Some case if the value is Ok.

Attributes

def toSeq: Seq[T]

Returns the Seq that is one element (the Ok value) or otherwise empty.

Returns the Seq that is one element (the Ok value) or otherwise empty.

Attributes

def toTry: Try[T]

Conversionerts the result to scala.util.Try.

Conversionerts the result to scala.util.Try.

Attributes

Type members

Classlikes

case class ResultIsErrException(error: Any) extends NoSuchElementException

An exception obtained by calling get on a Result.Err.

An exception obtained by calling get on a Result.Err.

Value parameters

error

the error value that was enclosed in the variant.

Attributes

Supertypes
trait Product
trait Equals
class NoSuchElementException
class RuntimeException
class Exception
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Show all

Inherited and Abstract types

type MirroredElemLabels <: Tuple

The names of the product elements

The names of the product elements

Attributes

Inherited from:
Mirror
type MirroredLabel <: String

The name of the type

The name of the type

Attributes

Inherited from:
Mirror