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

org.json4s.JsonKeyWriter.scala Maven / Gradle / Ivy

There is a newer version: 4.1.0-M8
Show newest version
package org.json4s

trait JsonKeyWriter[A] { self =>
  def write(key: A): String

  def contramap[B](f: B => A): JsonKeyWriter[B] =
    new JsonKeyWriter[B] {
      def write(key: B): String =
        self.write(f(key))
    }
}

object JsonKeyWriter {
  def apply[A](implicit a: JsonKeyWriter[A]): JsonKeyWriter[A] = a

  def of[A](f: A => String): JsonKeyWriter[A] =
    new JsonKeyWriter[A] {
      def write(key: A) = f(key)
    }

  def fromToString[A]: JsonKeyWriter[A] =
    of[A](_.toString)

  implicit val string: JsonKeyWriter[String] = of[String](x => x)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy