Result

org.llm4s.Result
@Stable
object Result

Companion object for Result types. Provides utility methods for creating and manipulating Result types. Includes methods for success, failure, fromOption, sequence, traverse, and combine. These methods allow users to easily create and handle Result types, providing a consistent and type-safe way to work with results in the LLM4S. Provides a clear and concise API for error handling and result manipulation. Provides methods for creating success and failure results, converting from Option types, sequencing and traversing lists of results, and combining two results into a tuple. This object is designed to be extensible for future requirements, allowing users to add additional utility methods as needed. It provides a consistent and type-safe way to handle results and errors in the LLM4S.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Result.type

Members list

Value members

Concrete methods

def combine[A, B](ra: Result[A], rb: Result[B]): Result[(A, B)]
def combine[A, B, C](ra: Result[A], rb: Result[B], rc: Result[C]): Result[(A, B, C)]
def failure[A](error: LLMError): Result[A]
def fromBoolean(condition: Boolean, error: LLMError): Result[Unit]

Create Result from boolean condition

Create Result from boolean condition

Attributes

def fromBooleanWithValue[A](condition: Boolean, successValue: A, error: LLMError): Result[A]

Create Result from boolean with custom success value

Create Result from boolean with custom success value

Attributes

def fromFuture[A](future: Future[A])(implicit ec: ExecutionContext): Future[Result[A]]
def fromOption[A](opt: Option[A], error: => LLMError): Result[A]
def safely[A](operation: => A): Result[A]
def sequence[A](results: List[Result[A]]): Result[List[A]]

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

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

Attributes

def success[A](value: A): Result[A]
def traverse[A, B](list: List[A])(f: A => Result[B]): Result[List[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

def validateAll[A](items: List[A])(validator: A => Result[A]): Either[List[LLMError], List[A]]