Defines an object join of Left and Right by Key resulting R.
Implementing this interface provides a join of Left and Right
to R with respect to Key, which can be used in
Join.Monadic[]. For instance, to declare that a Car has an
Engine with respect to CarId and they can be merged to
CarWithEngine, implementing Join[CarWithEngine, Carid, Car,
Engine] and passing it to Join.Monadic defines an accessor from
a Car to a CarWithEngine.
You need to implement four methods. First, leftKey() and
rightKey() defines how to resolve a Key from a Left and a
Right. Second, map() which maps values of Left to values of
Right. Finally, merge() defines how to merge two objects into
a value of R.
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. If a value lacks a mapping
result, that value is excluded from the merged result. If there
are multiple values in the resulting list with the same Key
(which is resolved by rightKey), then a source value with the
Key will be merged with one of them.
In the above example, you may want to have an implicit conversion
from a Car to an CarRelation to allow merging an Engine to a
Car.
implicitdef carRelation(car: Car): CarRelation = CarRelation(car)
// Single object mappingval car: Car = ???
val enginedCar: Option[CarWithEngine] = car.withEngine
// Multiple object mappingval cars: Seq[Car] = ???
val enginedCars: Seq[CarWithEngine] = cars.map(_.withEngine)
See the documentation of Join.Monadic for the detail of the
accessor behavior.
Defines an object join of
Left
andRight
byKey
resultingR
.Implementing this interface provides a join of
Left
andRight
toR
with respect toKey
, which can be used inJoin.Monadic[]
. For instance, to declare that aCar
has anEngine
with respect toCarId
and they can be merged toCarWithEngine
, implementingJoin[CarWithEngine, Carid, Car, Engine]
and passing it toJoin.Monadic
defines an accessor from aCar
to aCarWithEngine
.You need to implement four methods. First,
leftKey()
andrightKey()
defines how to resolve aKey
from aLeft
and aRight
. Second,map()
which maps values ofLeft
to values ofRight
. Finally,merge()
defines how to merge two objects into a value ofR
.Although the defined accessor is for a single instance, the
map
ping 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., themap
ping is actually a set-to-set mapping and the mapping function may not be total. If a value lacks a mapping result, that value is excluded from themerge
d result. If there are multiple values in the resulting list with the sameKey
(which is resolved byrightKey
), then a source value with theKey
will bemerge
d with one of them.In the above example, you may want to have an implicit conversion from a
Car
to anCarRelation
to allow merging anEngine
to aCar
.See the documentation of
Join.Monadic
for the detail of the accessor behavior.