Implementing this interface provides a mapping from Self to
Other, which can be used in HasA.Monadic[]. For instance, to
declare that a Car has an Engine, implementing HasA[Car,
Engine] and passing it to HasA.Monadic defines an accessor from
a Car to an Engine.
Although the defined accessor is for a single instance, the
mapping defines a list-to-list mapping. This allows you to define
an efficient way to retrieve multiple objects at once. The
resulting list may NOT be in the same order as the input
list or it may lack some elements correspond to those in the
input, i.e., the mapping is actually a set-to-set mapping and the
mapping function may not be total.
In the above example, you may want to have an implicit conversion
from a Car to CarRelation to allow accessing an Engine via a
Car.
implicitdef carRelation(car: Car): CarRelation = CarRelation(car)
// Single object mappingval car: Car = ???
val engine: Option[Engine] = car.toEngine
// Multiple object mappingval cars: Seq[Car] = ???
val engines: Seq[Engine] = cars.map(_.toEngine)
See the documentation of HasA.Monadic for the detail of the
accessor behavior.
Defines an object mapping from
Self
toOther
.Implementing this interface provides a mapping from
Self
toOther
, which can be used inHasA.Monadic[]
. For instance, to declare that aCar
has anEngine
, implementingHasA[Car, Engine]
and passing it toHasA.Monadic
defines an accessor from aCar
to anEngine
.Although the defined accessor is for a single instance, the mapping defines a list-to-list mapping. This allows you to define an efficient way to retrieve multiple objects at once. The resulting list may NOT be in the same order as the input list or it may lack some elements correspond to those in the input, i.e., the mapping is actually a set-to-set mapping and the mapping function may not be total.
In the above example, you may want to have an implicit conversion from a
Car
toCarRelation
to allow accessing anEngine
via aCar
.See the documentation of
HasA.Monadic
for the detail of the accessor behavior.