Result

opaque type Result[+A]

Value Result

Result is a container, which holds either 'value' or 'problem', which explains why value is not available.

Unlike Opt, Result is never void, even if there is no value, then, there must be a problem.

val r1: Result[Int] = "123".toIntResult

r1.tp   // Prints Result(123)

val r2: Result[Int] = "ABC".toIntResult

r2.tp   // Prints Result(Problem(For input string: "ABC"))
Source
__.scala

Def

inline def ~~: Stream[A]

Alias to "stream"

Alias to "stream"

Source
__.scala
inline def contains(v: A): Boolean

Check contains

Check contains

Returns 'true' if result contains given value

'false' - otherwise

  val r : Result[String] = "foo"

  r.contains("foo").tp  // Prints: true

  r.contains("bar").tp  // Prints: false
Source
__.scala
inline def drop(f: A => Boolean, p: A => Result.Problem): Result[A]

Reversed filter

Reversed filter

If the result value does satisfy given predicate, the problem is created with given function

The result with problem is not affected at all

val r : Result[String] = "foo"

r.drop(_.length < 2, "'" + _ + "' is too short").tp  // Prints Result(foo)

r.drop(_.length < 4, "'" + _ + "' is too short").tp  // Prints Result(Problem('foo' is too short))
Source
__.scala
inline def fornil[U](f: Result.Problem => U): Result[A]

Process problem

Process problem

Executes given function if there is a problem

Returns option itself

Source
__.scala
inline def forval[U](f: A => U): Result[A]

Process value

Process value

Executes given function with value

Does nothing if there is a problem

Returns result itself

Source
__.scala
inline def isProblem: Boolean

Problem check

Problem check

Returns true if there is a problem, false if there is a value

Source
__.scala
inline def isValue: Boolean

Value check

Value check

Returns true if there is a value, false if there is a problem

Source
__.scala
inline def map[B](f: A => B): Result[B]

Convert value

Convert value

Creates new result with value converted by the given function

Results with problem are cast to a new type without change

  Result("Abc").map(_.length).tp  // Prints: Result(3)
Source
__.scala
inline def mapResult(f: A => Result[B]): Result[B]

Map result

Map result

Results with problem are cast to a new type without change

Otherwise, value is converted to a new result by given function.

Source
__.scala
inline def or(default: => A): A

Value or default

Value or default

Returns result value, or if there is a problem, then given default value

Source
__.scala
inline def orResult(default: => Result[A]): Result[A]

Default result

Default result

Returns this result if it has value or given result otherwise

Source
__.scala

Get problem

Get problem

Returns problem, fails if there is a value

Generally use problemOpt instead

Source
__.scala

Optional problem

Optional problem

Returns problem option, which is void if there is a value

Source
__.scala
inline def process[U,W](f: A => U, pf: Result.Problem => W): Result[A]

Process value or problem

Process value or problem

Executes either given function for value or problem

Returns result itself

Source
__.scala
inline def recover(f: Result.Problem => Opt[A]): Result[A]

Optionally fix problem

Optionally fix problem

Results with value are not affected

Given function is run with problem and optional value is returned. If option is not void, result value is restored

Source
__.scala
inline def stream: Stream[A]

Stream

Stream

Returns single value stream or empty stream, if there is a problem

Source
__.scala
inline def take(f: A => Boolean, p: A => Result.Problem): Result[A]

Filter

Filter

If the result value does not satisfy given predicate, the problem is created with given function

The result with problem is not affected at all

val r : Result[String] = "foo"

r.take(_.length < 2, "'" + _ + "' is too long").tp  // Prints Result(Problem('foo' is too long))

r.take(_.length < 4, "'" + _ + "' is too long").tp  // Prints Result(foo)
Source
__.scala
inline def toTry: scala.util.Try[A]

Make Scala Try

Make Scala Try

Result is converted to scala.util.Try, which is a natural fit

Source
__.scala
inline def value: A

Get value

Get value

Returns result value, fails if there is a problem

Generally use valueOpt instead

Source
__.scala
inline def valueOpt: Opt[A]

Optional value

Optional value

Returns value option, which is void if there is a problem

Source
__.scala