Created
June 24, 2020 21:01
-
-
Save elyphas/accea1184be201fd401272f0f92ae381 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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