-
-
Save Jacoby6000/1536e794794b31227f296c124c3eb704 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
//reads input string, checks if its json, and if it is returns an encoded object of the first type that parses correctly. | |
def read[A](input: String)(implicit decoder: DecodeJson[A]): Option[A] = { // require that the decodeJson for type A be in scope | |
JsonParser.parse(input).toOption match { | |
case None => { | |
throw new AlgorithmException(s"input failed to parse.") | |
} | |
case Some(json: Json) => { | |
val decoded = decoder.decodeJson(json).toOption | |
decoded | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment