TypedRecord

info.fingo.spata.schema.TypedRecord
See theTypedRecord companion object
final class TypedRecord[KS <: Tuple, VS <: Tuple]

CSV record representation with type-safe access to its values. Typed records are created as result of schema validation.

Typed records values are accessed similarly to regular records, as values referenced by string keys. In contract to regular record, however, the keys are verified at compile time. See apply method for more. The returned value has already required type, as declared by schema definition:

val id: Int = record("id")

Thanks to this, in contrast to a regular Record, field access operation through apply and conversion to case class through to return required type directly, without wrapping it in Either.

For lineNum and rowNum description see Record.

Type parameters

KS

keys type - a tuple

VS

values type - a tuple

Value parameters

keys

actual record's keys

lineNum

last line number in source file this record is built from

rowNum

row number in source file this record comes from

values

actual record's values

Attributes

See also

CSVSchema for information about schema validation.

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def apply[K <: Key](key: K): Select[K, KS, VS]

Gets record value in type-safe manner.

Gets record value in type-safe manner.

The key is verified at compile time and has to be present in the record to use it. To achieve this, the provided key is required to have a singleton type. This works out of the box for literals, but has to be declared explicitly for variables:

val v1 = record("key") // OK
val key: "key" = "key"
val v2 = record(key) // OK
val wrong = "key"
val v3 = record(wrong) // does not compile

The returned value has the type which has been declared for given field by schema definition and validation (the proper type is inferred, you do not have to provide it explicitly): val value: Double = record("value") The formal return type, Select[K, KS, VS], is reduced to proper type through match type.

@param key the key of retrieved field @tparam K the key type - this is a singleton type representing the key @return field value

Attributes

inline def to[P <: Product](using m: ProductOf[P], ev: Union[Zip[MirroredElemLabels, <none>]] <:< Union[Zip[KS, VS]]): P

Converts typed record to a case class.

Converts typed record to a case class.

Because typed record has already got all the values properly typed, it may be safely converted to a case class. Assuming, that the record has a field name of type String and a field birthdate of type LocalDate, the conversion is as simple as that:

case class Person(name: String, birthdate: LocalDate)
val person = record.to[Person]

Please note that the conversion is name-based (case class field names have to match record fields), is case sensitive and only shallow conversion is supported. Case class may be narrower and effectively retrieve only a subset of record's fields.

It is possible to use a tuple instead of case class. In such a case the field names must match the "classic" tuple field naming convention: _1, _2 etc.

Type parameters

P

the Product type to converter this record to

Attributes

Returns

the requested case class or tuple

Concrete fields

val lineNum: Int
val rowNum: Int