Created
December 10, 2018 16:09
-
-
Save pfcoperez/81a96fae079530b1f002a084fc140792 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
import cats.data.Writer | |
import cats.syntax.writer._ | |
import cats.instances.all._ | |
type Metadata[Meta, T] = Writer[Meta, T] | |
object syntax { | |
implicit def metadataAs[Meta, T](m: Metadata[Meta, T]): T = m.run._2 | |
implicit class MetadataExt[T](x: T) { | |
def withMetadata[Meta](m: Meta): Metadata[Meta, T] = Writer.apply(m, x) | |
} | |
} | |
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