Last active
December 10, 2018 15:24
-
-
Save pfcoperez/ff55cadb42e3f436e1348004876b23ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Metadata[Meta, T](x: T, meta: Meta) | |
trait MetadataOps[T] { | |
def withMetadata[Meta](x: T, m: Meta): Metadata[Meta, T] | |
} | |
object syntax { | |
implicit def metadataAs[Meta, T](m: Metadata[Meta, T]): T = m.x | |
implicit class MetadataExt[T : MetadataOps](x: T) { | |
def withMetadata[Meta](m: Meta): Metadata[Meta, T] = implicitly[MetadataOps[T]].withMetadata(x, m) | |
} | |
} | |
implicit def evidences[T]: MetadataOps[T] = new MetadataOps[T] { | |
def withMetadata[Meta](x: T, m: Meta): Metadata[Meta, T] = Metadata[Meta, T](x, m) | |
} | |
case class AnEntity(name: String) | |
import syntax._ | |
val a = AnEntity("hello") | |
val aWithMeta = a.withMetadata(System.currentTimeMillis) | |
println(aWithMeta.name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment