The HList cons cell, which represents one part of an HList in linked
list style.
The HList cons cell, which represents one part of an HList in linked
list style.
Carries the information about the type of this element, plus the HList
type of the rest of the list.
You can use :+: to make this HList longer:
scala> val first = Type1("Value") :+: HNil first: net.liftweb.common.HLists.HCons[Type1,net.liftweb.common.HLists.HNil] = Type1(Value) :+: HNil scala> Type2("Other Value") :+: first res0: net.liftweb.common.HLists.HCons[Type2, net.liftweb.common.HLists.HCons[Type1, net.liftweb.common.HLists.HNil]] = Type2(Other Value) :+: Type1(Value) :+: HNil
The base trait for HLists.
The base trait for HLists. Functions that take HLists will need a type
parameter subtype of HList:
def myHListFunction[T <: HList](list: HList) = { println(s"This HList has ${list.length} items!") }
Provides the methods that can be used on an HList.
Provides the methods that can be used on an HList. These are set apart
here due to certain issues we can experience otherwise with the type variance
on the :+: class.
The last element of an HList.
The last element of an HList. This is the starting point for an HList,
and you can use :+: to start one based on it:
scala> Type1("Value") :+: HNil
res0: net.liftweb.common.HLists.HCons[Type1,net.liftweb.common.HLists.HNil] = Type1(Value) :+: HNil
The HNil singleton.
Basic support for heterogeneous lists, aka HLists.
An
HListcan be constructed like so:Above, we see that the
HListpreserved the value of the types of its members, otherwise we wouldn't have been able to fetchvalueandotherValue, respectively.Trying the same thing with a list won't work:
This is because
valueis not defined inBase. The inferred type of theListhas to be a common ancestor class or trait ofType1andType2, and no such type has avaluemethod.