PartialOf

org.llm4s.schema.PartialOf
See thePartialOf companion object
@Experimental
sealed trait PartialOf[A]

The type of a partly written A, and how to read one from the JSON a model has streamed so far: what client.streamStructuredOf[A] hands its callback.

For a case class A, Out is a named tuple with A's field names, each an Option of the field's partial value, None until the field has started to arrive:

case class LineItem(sku: String, quantity: Int)
case class Invoice(vendor: String, items: List[LineItem], status: Status)

// the Out of PartialOf[Invoice] is
// (vendor: Option[String], items: Option[List[(sku: Option[String], quantity: Option[Int])]], status: Option[Status])

A field's partial value follows its type:

  • String: the text so far;
  • a case class with fields: its own partial named tuple, recursively;
  • List, Vector and Seq: the elements so far, the last one partial when its type has partial values;
  • Option[T]: Some(None) once the model has written null, else T's partial value in a Some;
  • anything else (numbers, Boolean, enums, sum types, Set, BigDecimal): the value, only once complete, read with its uPickle Reader. A number is never shown while more digits may follow.

An instance is derived for any case class with fields (no derives clause), from the same field names, and the same @upickle.implicits.keys, that its SchemaOf and uPickle use. The type is computed at compile time rather than as a match type, since a match type cannot tell a case class from an enum or a sealed trait. To name it in a signature, take it from the instance: val invoices = summon[PartialOf[Invoice]] and def show(p: invoices.Out).

Type parameters

A

the case class being streamed

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Type members

Types

type Out

The partial value of A: a named tuple of Options, one per field of A.

The partial value of A: a named tuple of Options, one per field of A.

Attributes