Skip to content

Commit

Permalink
feat: Add Set compile-time support
Browse files Browse the repository at this point in the history
  • Loading branch information
Iltotore committed Sep 14, 2024
1 parent 2ea32c0 commit 6cf9c8a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions main/src/io/github/iltotore/iron/macros/ReflectUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class ReflectUtil[Q <: Quotes & Singleton](using val _quotes: Q):
TypeRepr.of[BigDecimal] -> decodeBigDecimal,
TypeRepr.of[BigInt] -> decodeBigInt,
TypeRepr.of[List[?]] -> decodeList,
TypeRepr.of[Set[?]] -> decodeSet,
TypeRepr.of[String] -> decodeString
)

Expand Down Expand Up @@ -377,3 +378,17 @@ class ReflectUtil[Q <: Quotes & Singleton](using val _quotes: Q):
case Apply(TypeApply(Select(Ident("List"), "apply"), _), List(values)) =>
decodeTerm(values, definitions).as[List[?]]
case _ => Left(DecodingFailure.Unknown)

/**
* Decode a [[Set]] term using only [[Set]]-specific cases.
*
* @param term the term to decode
* @param definitions the decoded definitions in scope
* @return the value of the given term found at compile time or a [[DecodingFailure]]
*/
def decodeSet(term: Term, definitions: Map[String, ?]): DecodingResult[Set[?]] =
term match
case Apply(TypeApply(Select(Ident("Set"), "apply"), _), List(values)) =>
decodeTerm(values, definitions).as[List[?]].map(_.toSet)
case _ => Left(DecodingFailure.Unknown)

0 comments on commit 6cf9c8a

Please sign in to comment.