meteor.syntax
See thesyntax companion object
trait syntax
Utility to help writing meteor.codec.Codec, meteor.codec.Encoder and meteor.codec.Decoder.
Examples:
import meteor.syntax._
import meteor.codec._
case class Author(
names: String,
age: Int
)
case class Book(
name: String,
author: Author,
coAuthor: Option[Author]
)
implicit val encoderForAuthor: Encoder[Author] = Encoder.instance { obj =>
Map(
"names" -> obj.names.asAttributeValue,
"age" -> obj.age.asAttributeValue
).asAttributeValue
}
implicit val encoderForBook: Encoder[Book] = Encoder.instance { obj =>
Map(
"name" -> obj.names.asAttributeValue,
"author" -> obj.age.asAttributeValue,
"coAuthor" -> obj.age.asAttributeValue,
).asAttributeValue
}
implicit val decoderForAuthor: Decoder[Author] = Decoder.instance { av =>
for {
names <- av.getAs[String]("names")
age <- av.getAs[Int]("age")
} yield Author(names, age)
}
implicit val decoderForBook: Decoder[Book] = Decoder.instance { av =>
for {
name <- av.getAs[String]("name")
author <- av.getAs[Author]("author")
coAuthor <- av.getOpt[Author]("coAuthor")
} yield Book(name, author, coAuthor)
}
Attributes
Members list
In this article