Skip to content

Commit

Permalink
Clarifying that these are not actually conditional return values
Browse files Browse the repository at this point in the history
  • Loading branch information
blast-hardcheese committed Oct 24, 2022
1 parent b2a2841 commit c80415a
Showing 1 changed file with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,9 @@ class CirceProtocolGenerator private (circeVersion: CirceModelGenerator, applyVa
q"$acc ++ $field"
}

Option(
q"""
q"""
${circeVersion.encoderObjectCompanion}.instance[${Type.Name(clsName)}](a => _root_.io.circe.JsonObject.fromIterable($allFields))
"""
)
}
val (readOnlyDefn, readOnlyFilter) = NonEmptyList.fromList(readOnlyKeys).fold((List.empty[Stat], identity[Term] _)) { roKeys =>
(
Expand All @@ -347,7 +345,7 @@ class CirceProtocolGenerator private (circeVersion: CirceModelGenerator, applyVa
)
}

Target.pure(encVal.map(encVal => q"""
Target.pure(Option(q"""
implicit val ${suffixClsName("encode", clsName)}: ${circeVersion.encoderObject}[${Type.Name(clsName)}] = {
..${readOnlyDefn};
${readOnlyFilter(encVal)}
Expand All @@ -373,14 +371,12 @@ class CirceProtocolGenerator private (circeVersion: CirceModelGenerator, applyVa
decVal <-
if (paramCount == 0) {
Target.pure(
Option[Term](
q"""
q"""
new _root_.io.circe.Decoder[${Type.Name(clsName)}] {
final def apply(c: _root_.io.circe.HCursor): _root_.io.circe.Decoder.Result[${Type.Name(clsName)}] =
_root_.scala.Right(${Term.Name(clsName)}())
}
"""
)
)
} else {
params.zipWithIndex
Expand Down Expand Up @@ -452,19 +448,17 @@ class CirceProtocolGenerator private (circeVersion: CirceModelGenerator, applyVa
}
.map { pairs =>
val (terms, enumerators) = pairs.unzip
Option(
q"""
q"""
new _root_.io.circe.Decoder[${Type.Name(clsName)}] {
final def apply(c: _root_.io.circe.HCursor): _root_.io.circe.Decoder.Result[${Type.Name(clsName)}] =
for {
..${enumerators}
} yield ${Term.Name(clsName)}(..${terms})
}
"""
)
}
}
} yield decVal.map(decVal => q"""
} yield Option(q"""
implicit val ${suffixClsName("decode", clsName)}: _root_.io.circe.Decoder[${Type.Name(clsName)}] = $decVal
""")
}
Expand Down

0 comments on commit c80415a

Please sign in to comment.