Skip to content

Instantly share code, notes, and snippets.

@elyphas
Created June 24, 2020 21:01
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 elyphas/accea1184be201fd401272f0f92ae381 to your computer and use it in GitHub Desktop.
Save elyphas/accea1184be201fd401272f0f92ae381 to your computer and use it in GitHub Desktop.
def unWrapJson(json: JsonValue) =
json match {
case JsonString(value) => value
case JsonDouble(value) => value.toString
}
sealed trait JsonValue
case class JsonString(value: String) extends JsonValue
case class JsonDouble(value: Double) extends JsonValue
trait UnWrapJson[ +A ] {
type Out
def apply[A]( a: A ): Out
}
object UnWrapJson {
implicit def unWrapJsonString: UnWrapJson[JsonValue] = new UnWrapJson [JsonValue] {
type Out = String
def apply[JsonString](json: JsonString) =
json match {
case JsonString(x) => x
}
}
}
def unWrap[T](json: T)(implicit unwrapjson: UnWrapJson[T]): unwrapjson.Out = unwrapjson(json)
val currentValue2: String = unWrap ( currentValue )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment