Result

kyo.Result$package.Result
opaque object Result

Companion object for Result type

Attributes

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

Members list

Type members

Classlikes

final class CatchingOps[E <: Throwable](dummy: Unit) extends AnyVal

Attributes

Supertypes
class AnyVal
trait Matchable
class Any
sealed abstract class Error[+E]

Represents an error in a Result.

Represents an error in a Result.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Fail[E]
class Panic
object Error

Attributes

Companion
class
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
Error.type
case class Fail[+E](error: E) extends Error[E]

Represents a failure in a Result.

Represents a failure in a Result.

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Error[E]
class Object
trait Matchable
class Any
Show all
object Fail

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Fail.type
case class Panic(exception: Throwable) extends Error[Nothing]

Represents a panic situation in a Result.

Represents a panic situation in a Result.

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Error[Nothing]
class Object
trait Matchable
class Any
Show all
object Panic

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Panic.type
object Success

Companion object for Success type

Companion object for Success type

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
Success.type

Types

opaque type Success[+A]

Represents a successful Result.

Represents a successful Result.

Attributes

Value members

Concrete methods

inline def apply[A](inline expr: => A): Result[Nothing, A]

Creates a Result from an expression that might throw an exception.

Creates a Result from an expression that might throw an exception.

Type parameters

A

The type of the successful result

Value parameters

expr

The expression to evaluate

Attributes

Returns

A Result containing either the successful value or a Panic with the caught exception

inline def catching[E <: Throwable]: CatchingOps[E]
def collect[E, A](seq: Seq[Result[E, A]]): Result[E, Seq[A]]

Collects a sequence of Results into a single Result containing a sequence of successful values.

Collects a sequence of Results into a single Result containing a sequence of successful values.

Type parameters

A

The type of the successful values

E

The type of the error

Value parameters

seq

The sequence of Results to collect

Attributes

Returns

A Result containing either a sequence of successful values or the first encountered error

inline def fail[E, A](inline error: E): Result[E, A]

Creates a failed Result.

Creates a failed Result.

Type parameters

A

The type of the successful value (not used in this case)

E

The type of the error

Value parameters

error

The error value

Attributes

Returns

A failed Result

def fromEither[E, A](either: Either[E, A]): Result[E, A]

Converts an Either to a Result.

Converts an Either to a Result.

Type parameters

A

The type of the successful value (Right value)

E

The type of the error (Left value)

Value parameters

either

The Either to convert

Attributes

Returns

A Result equivalent to the input Either

def fromTry[A](t: Try[A]): Result[Throwable, A]

Converts a Try to a Result.

Converts a Try to a Result.

Type parameters

A

The type of the successful value

Value parameters

t

The Try to convert

Attributes

Returns

A Result equivalent to the input Try

inline def panic[E, A](inline exception: Throwable): Result[E, A]

Creates a Result representing a panic situation.

Creates a Result representing a panic situation.

Type parameters

A

The type of the successful value (not used in this case)

E

The type of the error (not used in this case)

Value parameters

exception

The exception causing the panic

Attributes

Returns

A Result in a panic state

inline def success[E, A](inline value: A): Result[E, A]

Creates a successful Result.

Creates a successful Result.

Type parameters

A

The type of the successful value

E

The type of the error (not used in this case)

Value parameters

value

The successful value

Attributes

Returns

A successful Result

def unit[E]: Result[E, Unit]

Returns a successful Result containing unit.

Returns a successful Result containing unit.

Type parameters

E

The type of the error (not used in this case)

Attributes

Returns

A successful Result containing unit

Givens

Givens

inline given given_CanEqual_Result_Panic[E, A]: CanEqual[Result[E, A], Panic]
inline given given_CanEqual_Result_Result[E, A](using inline ce: CanEqual[A, A]): CanEqual[Result[E, A], Result[E, A]]

Extensions

Extensions

extension [E](self: Error[E])
def exception(using ev: E <:< Throwable): Throwable

Gets the exception from an Error.

Gets the exception from an Error.

Value parameters

ev

Evidence that E is a subtype of Throwable

Attributes

Returns

The exception

extension [E, A](self: Result[E, A])
def failure: Maybe[E]

Gets the error value if present.

Gets the error value if present.

Attributes

Returns

A Maybe containing the error value, or empty for non-Fail Results

inline def filter(inline p: A => Boolean): Result[E | NoSuchElementException, A]

Applies a predicate to the successful value of this Result.

Applies a predicate to the successful value of this Result.

Value parameters

p

The predicate to apply

Attributes

Returns

A new Result that fails if the predicate doesn't hold

inline def flatMap[E2, B](inline f: A => Result[E2, B]): Result[E | E2, B]

Applies a function to the successful value of this Result.

Applies a function to the successful value of this Result.

Type parameters

B

The type of the resulting successful value

E2

The error type of the resulting Result

Value parameters

f

The function to apply

Attributes

Returns

A new Result after applying the function

def flatten[E2, B](using ev: A <:< Result[E2, B]): Result[E | E2, B]

Flattens a nested Result.

Flattens a nested Result.

Type parameters

B

The successful type of the inner Result

E2

The error type of the inner Result

Value parameters

ev

Evidence that A is a Result

Attributes

Returns

The flattened Result

inline def fold[B](inline ifFailure: Error[E] => B)(inline ifSuccess: A => B): B

Folds the Result into a value.

Folds the Result into a value.

Type parameters

B

The type of the result of folding

Value parameters

ifFailure

Function to apply if the Result is a failure

ifSuccess

Function to apply if the Result is a success

Attributes

Returns

The result of applying the appropriate function

def get(using ev: E =:= Nothing): A

Gets the successful value.

Gets the successful value.

Value parameters

ev

Evidence that E is Nothing

Attributes

Returns

The successful value

Throws
NoSuchElementException

if the Result is a Fail

Throwable

if the Result is a Panic

inline def getOrElse[B >: A](inline default: => B): B

Gets the successful value or returns a default value.

Gets the successful value or returns a default value.

Type parameters

B

A supertype of A

Value parameters

default

The default value to return if the Result is not a Success

Attributes

Returns

The successful value or the default value

def isFail: Boolean

Checks if the Result is a Fail.

Checks if the Result is a Fail.

Attributes

Returns

true if the Result is a Fail, false otherwise

def isPanic: Boolean

Checks if the Result is a Panic.

Checks if the Result is a Panic.

Attributes

Returns

true if the Result is a Panic, false otherwise

def isSuccess: Boolean

Checks if the Result is a Success.

Checks if the Result is a Success.

Attributes

Returns

true if the Result is a Success, false otherwise

inline def map[B](inline f: A => B): Result[E, B]

Applies a function to the successful value of this Result.

Applies a function to the successful value of this Result.

Type parameters

B

The type of the resulting successful value

Value parameters

f

The function to apply

Attributes

Returns

A new Result after applying the function

inline def mapFail[E2](inline f: E => E2): Result[E2, A]

Applies a function to the error value of this Result.

Applies a function to the error value of this Result.

Type parameters

E2

The type of the resulting error

Value parameters

f

The function to apply

Attributes

Returns

A new Result after applying the function to the error

def orElse[E2, B >: A](alternative: => Result[E2, B]): Result[E | E2, B]

Returns this Result if it's a Success, or an alternative Result if it's not.

Returns this Result if it's a Success, or an alternative Result if it's not.

Type parameters

B

A supertype of A

E2

The error type of the alternative Result

Value parameters

alternative

The alternative Result to return if this Result is not a Success

Attributes

Returns

This Result if it's a Success, or the alternative Result

def panic: Maybe[Throwable]

Gets the panic exception if present.

Gets the panic exception if present.

Attributes

Returns

A Maybe containing the panic exception, or empty for non-Panic Results

inline def recover[B >: A](pf: PartialFunction[Error[E], B]): Result[E, B]

Recovers from an error by applying a partial function.

Recovers from an error by applying a partial function.

Type parameters

B

A supertype of A

Value parameters

pf

The partial function to apply to the error

Attributes

Returns

A new Result with the error potentially recovered

inline def recoverWith[E2, B >: A](pf: PartialFunction[Error[E], Result[E2, B]]): Result[E | E2, B]

Recovers from an error by applying a partial function that returns a new Result.

Recovers from an error by applying a partial function that returns a new Result.

Type parameters

B

A supertype of A

E2

The error type of the resulting Result

Value parameters

pf

The partial function to apply to the error

Attributes

Returns

A new Result with the error potentially recovered

def show: String

Returns a string representation of the Result.

Returns a string representation of the Result.

Attributes

Returns

A string describing the Result's state and value

def swap: Result[A, E]

Swaps the success and failure cases of the Result.

Swaps the success and failure cases of the Result.

Attributes

Returns

A new Result with success and failure swapped

def toEither: Either[E | Throwable, A]

Converts the Result to an Either.

Converts the Result to an Either.

Attributes

Returns

An Either with Left containing the error or exception, and Right containing the successful value

def toMaybe: Maybe[A]

Converts the Result to a Maybe.

Converts the Result to a Maybe.

Attributes

Returns

A Maybe containing the successful value, or empty for non-Success Results

def toTry(using ev: E <:< Throwable): Try[A]

Converts the Result to a Try.

Converts the Result to a Try.

Value parameters

ev

Evidence that E is a subtype of Throwable

Attributes

Returns

A Try containing the successful value, or Failure with the error

def value: Maybe[A]

Gets the successful value if present.

Gets the successful value if present.

Attributes

Returns

A Maybe containing the successful value, or empty for non-Success Results

inline def withFilter(inline p: A => Boolean): Result[E | NoSuchElementException, A]

Applies a predicate to the successful value of this Result.

Applies a predicate to the successful value of this Result.

Value parameters

p

The predicate to apply

Attributes

Returns

A new Result that fails if the predicate doesn't hold