syntax
The extension methods of llm4s, all in one object and none in scope until imported:
import org.llm4s.syntax.* // all of them
import org.llm4s.syntax.toResult // or one, by name
Try("42".toInt).toResult // Result[Int]
headers.get("x-request-id").toResult(NotFoundError("no request id", "x-request-id"))
new IllegalStateException("boom").toLLMError // LLMError
result.recover { case _: RateLimitError => "fallback" }.tap(println)
import org.llm4s.types.* brings in none of them, so it does not add toResult to every Try, Option and Future in the file.
Attributes
- Source
- syntax.scala
- Graph
-
- Supertypes
- Self type
-
syntax.type
Members list
Extensions
Extensions
The future's value as a Right, or its failure as a Left, mapped by Safety.fromThrowable: the returned future never fails because the original did. This is the one Future to AsyncResult conversion.
The future's value as a Right, or its failure as a Left, mapped by Safety.fromThrowable: the returned future never fails because the original did. This is the one Future to AsyncResult conversion.
Attributes
- Source
- syntax.scala
Right with the option's value, or Left(ifEmpty) for None.
Right with the option's value, or Left(ifEmpty) for None.
Value parameters
- ifEmpty
-
by-name: evaluated only when the option is
None
Attributes
- Source
- syntax.scala
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 anLLMError
Attributes
- Source
- syntax.scala
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
LLMErrorto a recovery value
Attributes
- Source
- syntax.scala
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
LLMErrorto a newResult[B]
Attributes
- Source
- syntax.scala
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
- Source
- syntax.scala
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
- Source
- syntax.scala
The Try's value as a Right, or its exception as a Left, mapped by Safety.fromThrowable.
The Try's value as a Right, or its exception as a Left, mapped by Safety.fromThrowable.
Attributes
- Source
- syntax.scala
This exception as an LLMError: Safety.fromThrowable.
