ResultOps

org.llm4s.syntax.syntax.ResultOps
final implicit class ResultOps[A](result: Result[A]) extends AnyVal

Enriches Result[A] with combinators for error handling and side effects.

These methods parallel standard Either and Try combinators but are typed specifically for LLMError on the left side, making the failure domain explicit at each call site.

Attributes

Graph
Supertypes
class AnyVal
trait Matchable
class Any

Members list

Value members

Concrete methods

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

Returns the success value, or default when the result is a Left.

Returns the success value, or default when the result is a Left.

Attributes

def mapError(f: LLMError => LLMError): Result[A]

Transforms the error value without changing the success type. Leaves Right values untouched.

Transforms the error value without changing the success type. Leaves Right values untouched.

Value parameters

f

transforms the LLMError; must return an LLMError

Attributes

def orElse[B >: A](alternative: => Result[B]): Result[B]

Returns this result when it is a Right, or evaluates alternative when it is a Left. The original error is discarded.

Returns this result when it is a Right, or evaluates alternative when it is a Left. The original error is discarded.

Attributes

def recover[B >: A](pf: PartialFunction[LLMError, B]): Result[B]

Converts a matching Left into a Right using the supplied partial function.

Converts a matching Left into a Right using the supplied partial function.

If the partial function is not defined for the error, the original Left is returned unchanged. Right values pass through without invoking pf.

Value parameters

pf

partial function from LLMError to a recovery value

Attributes

def recoverWith[B >: A](pf: PartialFunction[LLMError, Result[B]]): Result[B]

Converts a matching Left into a new Result using the supplied partial function.

Converts a matching Left into a new Result using the supplied partial function.

Useful when the recovery operation can itself fail. If the partial function is not defined for the error, the original Left is returned unchanged. Right values pass through without invoking pf.

Value parameters

pf

partial function from LLMError to a new Result[B]

Attributes

def tap(effect: A => Unit): Result[A]

Executes effect for its side effect when the result is a Right, then returns the original result unchanged. Useful for logging or metrics without breaking a for-comprehension chain.

Executes effect for its side effect when the result is a Right, then returns the original result unchanged. Useful for logging or metrics without breaking a for-comprehension chain.

Value parameters

effect

side-effecting function invoked on success; its return value is discarded

Attributes

def tapError(effect: LLMError => Unit): Result[A]

Executes effect for its side effect when the result is a Left, then returns the original result unchanged. Useful for logging errors without altering the failure path.

Executes effect for its side effect when the result is a Left, then returns the original result unchanged. Useful for logging errors without altering the failure path.

Value parameters

effect

side-effecting function invoked on failure; its return value is discarded

Attributes