Skip to content

Instantly share code, notes, and snippets.

@pfcoperez
Created December 10, 2018 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfcoperez/81a96fae079530b1f002a084fc140792 to your computer and use it in GitHub Desktop.
Save pfcoperez/81a96fae079530b1f002a084fc140792 to your computer and use it in GitHub Desktop.
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