Result

sealed trait Result[+Err, +A]

Result of a parser. Either a Success[A] or a Failure

Result of a parser. Either a Success[A] or a Failure

Type Params
A

The type of expected success result

class Object
trait Matchable
class Any
class Failure[Err]
class Success[A]

Value members

Abstract methods

def get: A

Returns the results's value.

Returns the results's value.

Throws
java.util.NoSuchElementException

if the result is a failure.

Since

1.7.0

Note

The result must not be a failure.

def isFailure: Boolean

Returns true if this is a Failure, false otherwise.

Returns true if this is a Failure, false otherwise.

Since

1.7.0

def isSuccess: Boolean

Returns true if this is a Success, false otherwise.

Returns true if this is a Success, false otherwise.

Since

1.7.0

Concrete methods

final def contains[B >: A](elem: B): Boolean

Returns true if this is a Success and its value is equal to elem (as determined by ==), returns false otherwise.

Returns true if this is a Success and its value is equal to elem (as determined by ==), returns false otherwise.

Value Params
elem

the element to test.

Returns

true if this is a Success value equal to elem.

Since

1.7.0

def exists(p: A => Boolean): Boolean

Returns false if Failure or returns the result of the application of the given predicate to the Success value.

Returns false if Failure or returns the result of the application of the given predicate to the Success value.

Since

1.7.0

def filterOrElse[Err_ >: Err](p: A => Boolean, msg: => Err_): Result[Err_, A]

Returns Success with the existing value of Success if this is a Success and the given predicate p holds for the right value, or Failure(msg) if this is a Success and the given predicate p does not hold for the right value, or Failure with the existing value of Failure if this is a Failure.

Returns Success with the existing value of Success if this is a Success and the given predicate p holds for the right value, or Failure(msg) if this is a Success and the given predicate p does not hold for the right value, or Failure with the existing value of Failure if this is a Failure.

Since

1.7.0

def flatMap[B, Err_ >: Err](f: A => Result[Err_, B]): Result[Err_, B]

Binds the given function across Success.

Binds the given function across Success.

Value Params
f

The function to bind across Success.

Since

1.7.0

def flatten[B, Err_ >: Err](ev: A <:< Result[Err_, B]): Result[Err_, B]

Returns the right value if this is right or this value if this is left

Returns the right value if this is right or this value if this is left

Equivalent to flatMap(id => id)

Since

1.7.0

def fold[B](ferr: Err => B, fa: A => B): B

Applies fa if this is a Failure or fb if this is a Success.

Applies fa if this is a Failure or fb if this is a Success.

Value Params
fa

the function to apply if this is a Success

ferr

the function to apply if this is a Failure

Returns

the results of applying the function

Since

1.7.0

def forall(f: A => Boolean): Boolean

Returns true if Failure or returns the result of the application of the given predicate to the Success value.

Returns true if Failure or returns the result of the application of the given predicate to the Success value.

Since

1.7.0

def foreach[U](f: A => U): Unit

Executes the given side-effecting function if this is a Success.

Executes the given side-effecting function if this is a Success.

Value Params
f

The side-effecting function to execute.

Since

1.7.0

def getOrElse[B >: A](or: => B): B

Returns the value from this Success or the given argument if this is a Failure.

Returns the value from this Success or the given argument if this is a Failure.

Since

1.7.0

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

The given function is applied if this is a Success.

The given function is applied if this is a Success.

Since

1.7.0

def orElse[B >: A, Err_ >: Err](or: => Result[Err_, B]): Result[Err_, B]

Returns this Success or the given argument if this is a Failure.

Returns this Success or the given argument if this is a Failure.

Since

1.7.0

def toEither: Either[Err, A]

Converts the Result into a Either where Failure maps to a Left[Err]

Converts the Result into a Either where Failure maps to a Left[Err]

Since

1.7.0

def toOption: Option[A]

Returns a Some containing the Success value if it exists or a None if this is a Failure.

Returns a Some containing the Success value if it exists or a None if this is a Failure.

Since

1.7.0

def toSeq: Seq[A]

Returns a Seq containing the Success value if it exists or an empty Seq if this is a Failure.

Returns a Seq containing the Success value if it exists or an empty Seq if this is a Failure.

Since

1.7.0

def toTry: Try[A]

Converts the Result into a Try where Failure maps to a plain Exception

Converts the Result into a Try where Failure maps to a plain Exception

Since

1.7.0