Result

utils.Result
See theResult companion object
enum Result[+T, +E]

A type representing either a successful value or an error.

Result[T, E] is similar to Either[E, T] but with more intuitive naming where T represents the success type and E represents the error type. This is commonly used for error handling without exceptions.

Type parameters

E

the type of the error value

T

the type of the success value

Attributes

Example
 val success: Result[Int, String] = Result.Success(42) val failure:
 Result[Int, String] = Result.Failure("Something went wrong")
val doubled = success.map(_ * 2) // Result.Success(84) val errorResult =
failure.map(_ * 2) // Result.Failure("Something went wrong") 
Companion
object
Graph
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Type members

Enum entries

final case class Failure[+T, +E](error: E)

Represents a failed result containing an error of type E.

Represents a failed result containing an error of type E.

Value parameters

error

the error value

Attributes

final case class Success[+T, +E](value: T)

Represents a successful result containing a value of type T.

Represents a successful result containing a value of type T.

Value parameters

value

the successful value

Attributes

Value members

Concrete methods

def option(): Option[A]
Extension method from Result

Converts a Result where both success and error types are the same to an Option. Success values are converted to Some, and Failure values are converted to None.

Converts a Result where both success and error types are the same to an Option. Success values are converted to Some, and Failure values are converted to None.

Attributes

Returns

Some(value) if Success, None if Failure