aboutsummaryrefslogtreecommitdiff
path: root/examples/src/main/scala/decode.scala
diff options
context:
space:
mode:
authorJon Pretty <jon.pretty@propensive.com>2017-11-08 11:17:53 +0000
committerJon Pretty <jon.pretty@propensive.com>2017-11-08 11:17:53 +0000
commit3f23cb5bca4ea8be889b714008a85141fe5e213c (patch)
tree8ba57fbf39c8f1892fc6b7adaf7810665e86de6c /examples/src/main/scala/decode.scala
parent1207383551b429560ac05e124349b24ff8b6dfda (diff)
downloadmagnolia-3f23cb5bca4ea8be889b714008a85141fe5e213c.tar.gz
magnolia-3f23cb5bca4ea8be889b714008a85141fe5e213c.tar.bz2
magnolia-3f23cb5bca4ea8be889b714008a85141fe5e213c.zip
Added better scaladocs and provide default values
Diffstat (limited to 'examples/src/main/scala/decode.scala')
-rw-r--r--examples/src/main/scala/decode.scala7
1 files changed, 3 insertions, 4 deletions
diff --git a/examples/src/main/scala/decode.scala b/examples/src/main/scala/decode.scala
index 1cc8a12..a5d1d67 100644
--- a/examples/src/main/scala/decode.scala
+++ b/examples/src/main/scala/decode.scala
@@ -12,18 +12,18 @@ object Decoder {
implicit val string: Decoder[String] = new Decoder[String] { def decode(str: String): String = str }
implicit val int: Decoder[Int] = new Decoder[Int] { def decode(str: String): Int = str.toInt }
- implicit def generic[T]: Decoder[T] = macro Magnolia.generic[T]
+ implicit def gen[T]: Decoder[T] = macro Magnolia.gen[T]
type Typeclass[T] = Decoder[T]
- def join[T](ctx: JoinContext[Decoder, T]): Decoder[T] = new Decoder[T] {
+ def combine[T](ctx: CaseClass[Decoder, T]): Decoder[T] = new Decoder[T] {
def decode(value: String) = {
val (name, values) = parse(value)
ctx.construct { param => param.typeclass.decode(values(param.label)) }
}
}
- def dispatch[T](ctx: DispatchContext[Decoder, T]): Decoder[T] = new Decoder[T] {
+ def dispatch[T](ctx: SealedTrait[Decoder, T]): Decoder[T] = new Decoder[T] {
def decode(param: String) = {
val (name, values) = parse(param)
val subtype = ctx.subtypes.find(_.label == name).get
@@ -60,6 +60,5 @@ object Decoder {
(name, parts(value.substring(end + 1, value.length - 1)).map(keyValue).toMap)
}
-
}