Created
January 5, 2017 22:46
-
-
Save zeryx/f64fee78cb4d4d5764508e630ddadd0c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Error:(26, 56) type mismatch; | |
found : argonaut.DecodeResult[algorithmia.TechSupport.Train] | |
required: argonaut.DecodeResult[algorithmia.TechSupport.Input] | |
Note: algorithmia.TechSupport.Train <: algorithmia.TechSupport.Input, but class DecodeResult is invariant in type A. | |
You may wish to define A as +A instead. (SLS 4.5) | |
(failReason, cursor) => Train.trainCodec.decode(json), |
This file contains hidden or 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 algorithmia.TechSupport | |
import algorithmia.TechSupport.Classes.DataPoint | |
import argonaut.Argonaut._ | |
import argonaut.CodecJson | |
import argonaut._ | |
/** | |
* Created by james on 05/01/17. | |
*/ | |
sealed trait Input | |
//TODO: Learn how implicits and type inference work, because this is some weird shit. | |
//also talk to Jacoby6000 on irc. | |
object Input { | |
implicit def inputCodec: CodecJson[Input] = { | |
def encoder(data: Input): Json = | |
data match { | |
case train: Train => Train.trainCodec.encode(train) | |
case predict: Predict => Predict.predictCodec.encode(predict) | |
} | |
def decoder(json: HCursor): DecodeResult[Input] = | |
Predict.predictCodec.decode(json).fold( | |
(failReason, cursor) => Train.trainCodec.decode(json), | |
successResult => DecodeResult.ok(successResult) | |
) | |
CodecJson[Input](encoder, decoder) | |
} | |
} | |
case class Train(labelData: Option[List[DataPoint]], labelFile: Option[String], namespace: Option[String]) extends Input | |
case class Predict(text: String, namespace: Option[String]) extends Input | |
object Train{ | |
implicit def trainCodec: CodecJson[Train] = | |
casecodec3(Train.apply, Train.unapply)( | |
"labelData", | |
"labelFile", | |
"namespace" | |
) | |
} | |
object Predict{ | |
implicit def predictCodec: CodecJson[Predict] = | |
casecodec2(Predict.apply, Predict.unapply)( | |
"text", | |
"namespace" | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment