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.

By Scalqa convention, method names, which return Result type, are ended with '_??' instead of word 'Result'

val r1: Result[Int] = "123".toInt_??

r1.tp   // Prints Result(123)

val r2: Result[Int] = "ABC".toInt_??

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

Def

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

Stream

Stream

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

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 => 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[A](inline 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[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
@scala.annotation.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
@scala.annotation.targetName("or_Result")
inline def or_??[A](inline default: => Result[A]): Result[A]
Source
__.scala

Get problem

Get problem

Returns problem, fails if there is a value

Generally use problem_? instead

Source
__.scala
@scala.annotation.targetName("problem_Opt")
inline def problem_?[A]: Opt[Result.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: 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[A](inline 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 take[A](inline f: A => Boolean, inline 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
def toTry[A]: scala.util.Try[A]

Make Scala Try

Make 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
@scala.annotation.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

Given

Inherited from
_givens
Source
_givens.scala
Inherited from
_givens
Source
_givens.scala
given givenDocTag[A](using val t: Given.DocTag[A]): Given.DocTag[Result[A]]
Inherited from
_givens
Source
_givens.scala
Inherited from
_givens
Source
_givens.scala
Inherited from
_givens
Source
_givens.scala

Implicit

implicit inline def implicitFromProblem[A](inline v: Result.Problem): Result[A]
Source
__.scala
implicit inline def implicitFromValue[A](inline v: A): Result[A]
Source
__.scala
implicit inline def implicitToBoolean[A](inline v: Result[A]): Boolean
Source
__.scala