Result

object Result extends _givens
Source
__.scala
class _givens
class Object
trait Matchable
class Any

Member

trait Problem

Problem explaining why result value is not available.

Companion
object
Source
__.scala
trait Problem

Problem explaining why result value is not available.

Companion
object
Source
__.scala

Def

@targetName("stream")
def ~[A]: ~[A]

Stream

Stream

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

Source
__.scala
inline def apply[A](inline v: A | Problem): Result[A]
Source
__.scala
inline def contains[A](value: Any): 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[A](inline f: A => Boolean, inline p: A => 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
def fail[A](message: String): Result[A]
Source
__.scala
inline def fornil[A](inline f: Problem => U): Result[A]

Process problem

Process problem

Executes given function if there is a problem

Returns option itself

Source
__.scala
inline def forval[A](inline 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[A]: Boolean

Problem check

Problem check

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

Source
__.scala
inline def isValue[A]: Boolean

Value check

Value check

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

Source
__.scala
inline def map[A](inline 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

  "Abc".??.map(_.length).tp  // Prints: Result(3)
Source
__.scala
@targetName("map_Result")
inline def map_??[A](inline 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[A](inline default: => A): A

Value or default

Value or default

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

Source
__.scala
@targetName("or_Result")
inline def or_??[A](inline default: => Result[A]): Result[A]
Source
__.scala
def problem[A]: Problem

Get problem

Get problem

Returns problem, fails if there is a value

Generally use problem_? instead

Source
__.scala
@targetName("problem_Opt")
inline def problem_?[A]: Opt[Problem]

Optional problem

Optional problem

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

Source
__.scala
inline def process[A](inline f: A => U, inline pf: 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[A](inline f: 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 take[A](inline f: A => Boolean, inline p: A => 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
def toTry[A]: Try[A]

To Scala Try

To Scala Try

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

Source
__.scala
def value[A]: A

Get value

Get value

Returns result value, fails if there is a problem

Generally use value_? instead

Source
__.scala
@targetName("value_Opt")
inline def value_?[A]: Opt[A]

Optional value

Optional value

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

Source
__.scala

To

Type alias

Type alias

Shortcut to Result.Problem

Source
__.scala

Companion alias

Companion alias

Shortcut to Result.Problem

Source
__.scala