Record class with constant-time field access.
It provides extensible records in a different way than %
. There are following differences compared to %
.
- Field access is faster (constant time)
- Creation is faster
- Update time grows significantly when record size grows
- Compilation is a bit slower
- No implicit upcast
Example
val r = ArrayRecord(name = "tarao", age = 3)
// val r: com.github.tarao.record4s.ArrayRecord[(("name", String), ("age", Int))] = ArrayRecord(name = tarao, age = 3)
r.name
// val res0: String = tarao
r.age
// val res1: Int = 3
Attributes
- Companion
- object
- Source
- ArrayRecord.scala
- Graph
-
- Supertypes
-
trait Dynamicclass ProductRecordtrait Producttrait Equalstrait Recordclass Objecttrait Matchableclass AnyShow all
- Known subtypes
-
class VectorRecord
Members list
Value members
Concrete methods
Alias for updated
Alias for concat
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 = ArrayRecord(name = "tarao", age = 3, email = "[email protected]") val r2 = r1(select.name.age) // val r2: com.github.tarao.record4s.ArrayRecord[(("name", String), ("age", Int))] = ArrayRecord(name = tarao, age = 3) val r3 = r1(select.name(rename = "nickname").age) // val r3: com.github.tarao.record4s.ArrayRecord[(("nickname", String), ("age", Int))] = ArrayRecord(nickname = tarao, age = 3)
- Source
- ArrayRecord.scala
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 = ArrayRecord(name = "tarao", age = 3, email = "[email protected]") val r2 = r1(unselect.email) // val r2: com.github.tarao.record4s.ArrayRecord[(("name", String), ("age", Int))] = ArrayRecord(name = tarao, age = 3)
- Source
- ArrayRecord.scala
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 = ArrayRecord(name = "tarao", age = 3) val r2 = ArrayRecord(age = 4, email = "[email protected]") val r3 = r1 ++ r2 // val r3: com.github.tarao.record4s.ArrayRecord[(("name", String), ("age", Int), ("email", String))] = ArrayRecord(name = tarao, age = 4, email = [email protected])
- Source
- ArrayRecord.scala
Attributes
- Definition Classes
-
ProductRecord -> Product
- Source
- ArrayRecord.scala
Attributes
- Source
- ArrayRecord.scala
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 [T <: Tuple](p: ArrayRecord[(("name", String) *: T) & Tag[Person]]) { def firstName: String = p.name.split(" ").head } } val r = ArrayRecord(name = "tarao fuguta", age = 3).tag[Person] r.firstName // val res0: String = tarao
- Source
- ArrayRecord.scala
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 = ArrayRecord(name = "tarao", age = 3) r.to[Person] // val res0: Person = Person(tarao,3)
- Source
- ArrayRecord.scala
Convert to a record of type %
.
Convert to a record of type %
.
Attributes
- Returns
-
a record of type
%
- Example
-
val r1 = ArrayRecord(name = "tarao", age = 3) // val r1: com.github.tarao.record4s.ArrayRecord[(("name", String), ("age", Int))] = ArrayRecord(name = tarao, age = 3) r1.toRecord // val res0: com.github.tarao.record4s.%{val name: String; val age: Int} = %(name = tarao, age = 3)
- Source
- ArrayRecord.scala
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 = ArrayRecord(name = "tarao", age = 3) r1.toTuple // val res0: (("name", String), ("age", Int)) = ((name,tarao),(age,3))
- Source
- ArrayRecord.scala
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 = ArrayRecord(name = "tarao", age = 3, email = "[email protected]") // val r1: com.github.tarao.record4s.ArrayRecord[(("name", String), ("age", Int), ("email", String))] = ArrayRecord(name = tarao, age = 3, email = [email protected]) val r2 = r1.upcast[(("name", String), ("age", Int))] // val r2: com.github.tarao.record4s.ArrayRecord[(("name", String), ("age", Int))] = ArrayRecord(name = tarao, age = 3)
- Source
- ArrayRecord.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 = ArrayRecord(name = "tarao") + (age = 3, email = "[email protected]") // val r: com.github.tarao.record4s.ArrayRecord[(("name", String), ("age", Int), ("email", String))] = ArrayRecord(name = tarao, age = 3, email = [email protected])
- Source
- ArrayRecord.scala
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 = ArrayRecord(name = "tarao", age = 3) r1.values // val res0: (String, Int) = (tarao,3)
- Source
- ArrayRecord.scala
Inherited methods
Attributes
- Definition Classes
-
ProductRecord -> Equals
- Inherited from:
- ProductRecord
- Source
- ArrayRecord.scala
Compares the receiver object (this
) with the argument object (that
) for equivalence.
Compares the receiver object (this
) with the argument object (that
) for equivalence.
Any implementation of this method should be an equivalence relation:
- It is reflexive: for any instance
x
of typeAny
,x.equals(x)
should returntrue
. - It is symmetric: for any instances
x
andy
of typeAny
,x.equals(y)
should returntrue
if and only ify.equals(x)
returnstrue
. - It is transitive: for any instances
x
,y
, andz
of typeAny
ifx.equals(y)
returnstrue
andy.equals(z)
returnstrue
, thenx.equals(z)
should returntrue
.
If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is usually necessary to override hashCode
to ensure that objects which are "equal" (o1.equals(o2)
returns true
) hash to the same scala.Int. (o1.hashCode.equals(o2.hashCode)
).
Value parameters
- that
-
the object to compare against this object for equality.
Attributes
- Returns
-
true
if the receiver object is equivalent to the argument;false
otherwise. - Definition Classes
- Inherited from:
- ProductRecord
- Source
- ArrayRecord.scala
Attributes
- Definition Classes
-
ProductRecord -> Product
- Inherited from:
- ProductRecord
- Source
- ArrayRecord.scala
Attributes
- Definition Classes
-
ProductRecord -> Product
- Inherited from:
- ProductRecord
- Source
- ArrayRecord.scala
Attributes
- Definition Classes
-
ProductRecord -> Product
- Inherited from:
- ProductRecord
- Source
- ArrayRecord.scala
Attributes
- Inherited from:
- Product
Attributes
- Inherited from:
- Product
Stringify the record.
Stringify the record.
The order of key-value pairs is exactly the same as that of the static field types.
Attributes
- Definition Classes
-
ProductRecord -> Any
- Inherited from:
- ProductRecord
- Source
- ArrayRecord.scala