Created
October 30, 2019 00:58
-
-
Save zeryx/bc9d903cb1723dcf367657922223edb0 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
package com.algorithmia.handler | |
import play.api.libs.json._ | |
import scala.util.{Failure, Success, Try} | |
trait AbstractAlgorithm[I <: AnyVal, O <: AnyVal] { | |
def apply(input:I): Try[O] | |
def load(): Try[Unit] = Success(()) | |
implicit def inputReader: Reads[I] = Try(implicitly[Reads[I]]) match { | |
case Failure(_) => Json.reads[I] | |
case Success(s: Reads[I]) => s | |
} | |
implicit def outputWriter: Writes[O] = Try(implicitly[Writes[O]]) match { | |
case Failure(_) => Json.writes[O] | |
case Success(s: Writes[O]) => s | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment