Record

com.github.tarao.record4s.Record
See theRecord companion trait
object Record

Attributes

Companion
trait
Source
Record.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Record.type

Members list

Type members

Classlikes

final class Extensible[R <: %](record: R) extends AnyVal, Dynamic

Attributes

Source
Record.scala
Supertypes
trait Dynamic
class AnyVal
trait Matchable
class Any
final class RecordLikeRecord[R <: %] extends RecordLike[R]

Attributes

Source
Record.scala
Supertypes
trait RecordLike[R]
class Object
trait Matchable
class Any

Value members

Concrete methods

inline def from[T : RecordLike, RR <: %](x: T)(implicit evidence$1: RecordLike[T], Aux[T, RR]): RR

Construct a record from something else.

Construct a record from something else.

Type parameters

T

some type given RecordLike[T]

Value parameters

x

something that is record like

Attributes

Returns

a record

Example
 case class Person(name: String, age: Int)
 val p = Person("tarao", 3)
 val r = Record.from(p)
 // val r: com.github.tarao.record4s.%{val name: String; val age: Int} = %(name = tarao, age = 3)
Source
Record.scala
def lookup[R <: %, L <: String & Singleton, Out](record: R, label: L)(using Aux[R, L, Out]): Out

Get the field value of specified label.

Get the field value of specified label.

It is essentially the same as record.{label} but it can access to fields hidden by own methods of class %.

Value parameters

label

a string literal field name

record

a record

Attributes

Returns

the value of the field named by label

Example
 val r = %(value = 3, toString = 10)
 r.value
 // val res0: Int = 3
 r.toString
 // val res1: String = %(value = 3, toString = 10)
 Record.lookup(r, "value")
 // val res2: Int = 3
 Record.lookup(r, "toString")
 // val res3: Int = 10
Source
Record.scala

Concrete fields

val empty: %

An empty record.

An empty record.

Attributes

Source
Record.scala

Givens

Givens

given canEqualReflexive[R <: %]: CanEqual[R, R]

Attributes

Source
Record.scala
transparent inline given recordLike[R <: %]: RecordLike[R]

Attributes

Source
Record.scala

Extensions

Extensions

extension [R <: %](record: R)
inline def +: Extensible[R]

Alias for updated

Alias for updated

Attributes

Source
Record.scala
inline def ++[R2 : RecordLike, RR <: %](other: R2)(implicit evidence$3: RecordLike[R2], Aux[R, R2, RR]): RR

Alias for concat

Alias for concat

Attributes

Source
Record.scala
inline def apply[S <: Tuple, RR <: %](s: Selector[S])(using Aux[R, S, RR]): RR

Create a new record by selecting some fields of an existing record.

Create a new record by selecting some fields of an existing record.

Type parameters

RR

type of the new record

S

list of selected field as a Tuple

Value parameters

s

selection of fields created by select

Attributes

Returns

a new record with the selected fields

Example
 val r1 = %(name = "tarao", age = 3, email = "[email protected]")
 val r2 = r1(select.name.age)
 // val r2: com.github.tarao.record4s.%{val name: String; val age: Int} = %(name = tarao, age = 3)
 val r3 = r1(select.name(rename = "nickname").age)
 // val r3: com.github.tarao.record4s.%{val nickname: String; val age: Int} = %(nickname = tarao, age = 3)
Source
Record.scala
inline def apply[U <: Tuple, RR <: %](u: Unselector[U])(using Aux[R, U, RR], RecordLike[RR], R <:< RR): RR

Create a new record by unselecting some fields of an existing record.

Create a new record by unselecting some fields of an existing record.

Type parameters

RR

type of the new record

U

list of unselected field as a Tuple

Value parameters

u

unselection of fields created by unselect

Attributes

Returns

a new record without the unselected fields

Example
 val r1 = %(name = "tarao", age = 3, email = "[email protected]")
 val r2 = r1(unselect.email)
 // val r2: com.github.tarao.record4s.%{val name: String; val age: Int} = %(name = tarao, age = 3)
Source
Record.scala
inline def as[R2 >: R <: % : RecordLike]: R2

Upcast the record to specified type.

Upcast the record to specified type.

Type parameters

R2

target type

Attributes

Returns

a record containing only fields in the target type

Example
 val r1 = %(name = "tarao", age = 3, email = "[email protected]")
 // val r1: com.github.tarao.record4s.%{val name: String; val age: Int; val email: String} = %(name = tarao, age = 3, email = [email protected])
 val r2 = r1.as[% { val name: String; val age: Int }]
 // val r2: com.github.tarao.record4s.%{val name: String; val age: Int} = %(name = tarao, age = 3)
Source
Record.scala
inline def concat[R2 : RecordLike, RR <: %](other: R2)(implicit evidence$2: RecordLike[R2], Aux[R, R2, RR]): RR

Concatenate this record and another record.

Concatenate this record and another record.

If the both record has a field of the same name, then it takes the field from the latter record.

Type parameters

R2

a record type (given RecordLike[R2])

Value parameters

other

a record to concatenate

Attributes

Returns

a new record which has the both fields from this record and other

Example
 val r1 = %(name = "tarao", age = 3)
 val r2 = %(age = 4, email = "[email protected]")
 val r3 = r1 ++ r2
 // val r3: com.github.tarao.record4s.%{val name: String; val age: Int; val email: String} = %(name = tarao, age = 4, email = [email protected])
Source
Record.scala
def tag[T]: R & Tag[T]

Give a type tag to this record.

Give a type tag to this record.

Type parameters

T

an arbitrary type used as a tag

Attributes

Returns

the same record with a tag type

Example
 trait Person; object Person {
   extension (p: %{val name: String} & Tag[Person]) {
     def firstName: String = p.name.split(" ").head
   }
 }
 val r = %(name = "tarao fuguta", age = 3).tag[Person]
 r.firstName
 // val res0: String = tarao
Source
Record.scala
def to[To](using conv: Converter[R, To]): To

Convert this record to a To.

Convert this record to a To.

Type parameters

To

a type to which the record is converted

Attributes

Returns

a new product instance

Example
 case class Person(name: String, age: Int)
 val r = %(name = "tarao", age = 3)
 r.to[Person]
 // val res0: Person = Person(tarao,3)
Source
Record.scala
inline def toTuple(using r: RecordLike[R]): Zip[ElemLabels, ElemTypes]

Convert this record to a Tuple.

Convert this record to a Tuple.

Attributes

Returns

fields of label-value pairs as a tuple

Example
 val r1 = %(name = "tarao", age = 3)
 r1.toTuple
 // val res0: (("name", String), ("age", Int)) = ((name,tarao),(age,3))
Source
Record.scala

Extend the record by fields.

Extend the record by fields.

If a new field has the same name as the existing field, then the new field overrides the old one.

Attributes

Returns

an object to define new fields

Example
 val r = %(name = "tarao") + (age = 3, email = "[email protected]")
 // val r: com.github.tarao.record4s.%{val name: String; val age: Int; val email: String} = %(name = tarao, age = 3, email = [email protected])
Source
Record.scala
inline def values(using r: RecordLike[R]): ElemTypes

Return values of this record as a Tuple.

Return values of this record as a Tuple.

Attributes

Returns

values of the record as a tuple

Example
 val r1 = %(name = "tarao", age = 3)
 r1.values
 // val res0: (String, Int) = (tarao,3)
Source
Record.scala