Trait/Object

com.github.tarao.bullet

HasA

Related Docs: object HasA | package bullet

Permalink

trait HasA[Self, Other] extends AnyRef

Defines an object mapping from Self to Other.

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.

object HasEngine extends HasA[Car, Engine] {
  def map(from: Seq[Car]): Seq[Engine] =
    ??? // implement your mapping
}

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

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.

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

// Single object mapping
val car: Car = ???
val engine: Option[Engine] = car.toEngine

// Multiple object mapping
val cars: Seq[Car] = ???
val engines: Seq[Engine] = cars.map(_.toEngine)

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

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

Abstract Value Members

  1. abstract def map(from: Seq[Self]): Seq[Other]

    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. final def eq(arg0: AnyRef): Boolean

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

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

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

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

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

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

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

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

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

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

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

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped