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

iozhik.OpenEnum.scala Maven / Gradle / Ivy

There is a newer version: 9.711.0
Show newest version
package iozhik

import io.circe.Encoder

/** Indicates that the enumeration is open and can accept values beyond those already specified.
  */
sealed trait OpenEnum[+T]

object OpenEnum {
  case class Known[T](value: T)        extends OpenEnum[T]
  case class Unknown[T](value: String) extends OpenEnum[T]

  def apply[T](value: T): OpenEnum[T] = Known(value)

  implicit def encoder[T: Encoder]: Encoder[OpenEnum[T]] = {
    case Known(value)   => Encoder[T].apply(value)
    case Unknown(value) => Encoder[String].apply(value)
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy