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

net.hamnaberg.json.collection.extension.Extension.scala Maven / Gradle / Ivy

There is a newer version: 2.5
Show newest version
package net.hamnaberg.json.collection.extension

import net.hamnaberg.json.collection.Extensible
import org.json4s.JField

trait Extension[Like, A] { self =>
  def apply(like: Like): A
  def unapply(like: Like) : Option[A] = Some(apply(like))
  def asJson(ext: A, parent: Extensible[_]): Seq[JField]

  def ++[B](b: Extension[Like, B]): Extension[Like, (A, B)] = new Extension[Like, (A, B)] {
    def apply(like: Like) = self.apply(like) -> b.apply(like)

    def asJson(ext: (A, B), parent: Extensible[_]) = self.asJson(ext._1, parent) ++ b.asJson(ext._2, parent)
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy