All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.scalaland.chimney.javacollections.internal.TransformOrUpcast.scala Maven / Gradle / Ivy

package io.scalaland.chimney.javacollections.internal

import io.scalaland.chimney.Transformer

/** Since [[io.scalaland.chimney.Transformer]] is NOT automatically provided for identity/subtype transformation,
  * and we want to allow such things without enabling whole recursive auto-derivation we use this trick.
  */
trait TransformOrUpcast[From, To] {
  def transform(src: From): To
}
object TransformOrUpcast extends TransformOrUpcastLowPriority {

  implicit def userProvidedTransformerExists[From, To](implicit
      transformer: Transformer[From, To]
  ): TransformOrUpcast[From, To] =
    from => transformer.transform(from)
}
private[internal] trait TransformOrUpcastLowPriority {

  implicit def sourceIsSubtypeOfTarget[From, To](implicit ev: From <:< To): TransformOrUpcast[From, To] =
    from => ev(from)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy