Skip to content

Instantly share code, notes, and snippets.

@zeryx
Created October 30, 2019 00:58
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 zeryx/bc9d903cb1723dcf367657922223edb0 to your computer and use it in GitHub Desktop.
Save zeryx/bc9d903cb1723dcf367657922223edb0 to your computer and use it in GitHub Desktop.
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