Result

org.llm4s.types.`package`.Result
object Result

Helpers for building and combining Result values (Either[LLMError, A]).

val all: Result[Seq[Int]] = Result.traverse(lines)(parseLine)

Attributes

Source
package.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Result.type

Members list

Value members

Concrete methods

def failure[A](error: LLMError): Result[A]

Wraps error as a failed result (Left(error)).

Wraps error as a failed result (Left(error)).

Attributes

Source
package.scala
def fromOption[A](opt: Option[A], error: => LLMError): Result[A]

Right with the option's value, or Left(error) for None.

Right with the option's value, or Left(error) for None.

Value parameters

error

by-name: evaluated only when opt is None

Attributes

Source
package.scala
def safely[A](operation: => A): Result[A]

Runs operation and returns its value as a Right. A non-fatal exception it throws becomes a Left, mapped by Safety.fromThrowable: a CancelledError, a NetworkError (a connection failure or timeout) or, for anything else, an UnknownError.

Runs operation and returns its value as a Right. A non-fatal exception it throws becomes a Left, mapped by Safety.fromThrowable: a CancelledError, a NetworkError (a connection failure or timeout) or, for anything else, an UnknownError.

Attributes

Source
package.scala
def sequence[A](results: Seq[Result[A]]): Result[Seq[A]]

Collects results into a result of their values: the values in order, or the first Left.

Collects results into a result of their values: the values in order, or the first Left.

Attributes

Source
package.scala
def success[A](value: A): Result[A]

Wraps value as a successful result (Right(value)).

Wraps value as a successful result (Right(value)).

Attributes

Source
package.scala
def traverse[A, B](items: Seq[A])(f: A => Result[B]): Result[Seq[B]]

Applies f to each element in order and collects the values, stopping at the first Left: f is not called on any element after the first failure, so side effects and expensive work in f stop there too.

Applies f to each element in order and collects the values, stopping at the first Left: f is not called on any element after the first failure, so side effects and expensive work in f stop there too.

Attributes

Source
package.scala
def validateAll[A](items: Seq[A])(validator: A => Result[A]): Either[Seq[LLMError], Seq[A]]

Runs validator on every item and collects every error, unlike traverse, which stops at the first: Left with all the errors in item order when any item fails, otherwise Right with the validated values in order.

Runs validator on every item and collects every error, unlike traverse, which stops at the first: Left with all the errors in item order when any item fails, otherwise Right with the validated values in order.

Attributes

Source
package.scala