Object/Trait

com.github.tarao.bullet

HasA

Related Docs: trait HasA | package bullet

Permalink

object HasA

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

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. object Monadic

    Permalink

    A factory of a monad for a one-to-one object mapping relation.

    A factory of a monad for a one-to-one object mapping relation.

    To initially create a monad instance, use HasA.Monadic.apply() together with a source object of the mapping and an instance of HasA[] which describes a mapping. For instance, a monad for a mapping from a Car to an Engine defined by a HasA[Car, Engine] can be generated as the following.

    val hasEngine: HasA[Car, Engine] = ???
    val car: Car = ???
    val m = HasA.Monadic(car, hasEngine)

    A monad can implicitly be converted to an option value of the target type of the mapping by internally invoking HasA.map() in the conversion.

    val engine: Option[Engine] = m

    Since it is a monad, the value can mapped to another value in a for comprehension. (Assume that an Engine has id field of type Long in the next example.)

    val id: Option[Long] = for { e <- m } yield (e.id)

    Note that the e in the above example, i.e., the argument of a function passed to flatMap() or map() of the monad, is an Engine. You don't need to look inside the option value in this way. If the resulting option value is None, i.e., HasA.map() does not return a value for the source of the mapping, then the body of the function passed to flatMap() or map() never be invoked.

    A list of monadic values can also be converted to a list of the target list type.

    val cars: Seq[Car] = ???
    val ms = cars.map { car => HasA.Monadic(car, hasEngine) }
    val engines: Seq[Engine] = ms

    In this case, cars are mapped to engines by HasA.map() all at once. You can of course use a for comprehension for further operations.

    val ids: Seq[Long] = ms.map { m => for { e <- m } yield (e.id) }

    If you aim to achieve an efficient object mapping by converting a list value at once via HasA.map() --- this is the most common reason for using the monadc object mapping ---, DO NOT trigger the implicit conversion inside the loop.

    val ids: Seq[Long] = ms.map { m =>
      val id: Option[Long] /* !!! HasA.map() is called here !!! */ = for {
        e <- m
      } yield (e.id)
      id
    }.flatten

    It is not difficult to notice the misuse in this way since the object must be recieved as an Option[Long] not a Long to trigger the conversion for each element.

  5. final def asInstanceOf[T0]: T0

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

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  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( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped