Trait/Object

com.github.tarao.bullet

Join

Related Docs: object Join | package bullet

Permalink

trait Join[R, Key, Left, Right] extends HasA[Left, Right]

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.

object HasEngine
    extends Join[CarWithEngine, CarId, Car, Engine] {
  def leftKey(car: Car): CarId = ???
  def rightKey(engine: Engine): CarId = ???
  def map(from: Seq[Car]): Seq[Engine] = ???
  def merge(car: Car, engine: Engine): CarWithEngine = ???
}

// An accessor provider
case class CarRelation(car: Car) {
  def withEngine = Join.Monadic(car, HasEngine)
}

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.

implicit def carRelation(car: Car): CarRelation = CarRelation(car)

// Single object mapping
val car: Car = ???
val enginedCar: Option[CarWithEngine] = car.withEngine

// Multiple object mapping
val cars: Seq[Car] = ???
val enginedCars: Seq[CarWithEngine] = cars.map(_.withEngine)

See the documentation of Join.Monadic for the detail of the accessor behavior.

Source
Join.scala
Linear Supertypes
HasA[Left, Right], AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Join
  2. HasA
  3. AnyRef
  4. Any
  1. Hide All
  2. Show all
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def leftKey(left: Left): Key

    Permalink
  2. abstract def map(from: Seq[Left]): Seq[Right]

    Permalink
    Definition Classes
    HasA
  3. abstract def merge(left: Left, right: Right): R

    Permalink
  4. abstract def rightKey(left: Right): Key

    Permalink

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. def default: Option[Right]

    Permalink
  7. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  8. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  9. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  10. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  11. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  12. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  13. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  14. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  15. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  16. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  17. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  18. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  19. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. def withFallback(fallback: Fallback[Right]): Join[R, Key, Left, Right]

    Permalink

Inherited from HasA[Left, Right]

Inherited from AnyRef

Inherited from Any

Ungrouped