-
Notifications
You must be signed in to change notification settings - Fork 14
Add article compile-time data contracts article with Scala 3 macros #354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…cros and schema validation
daniel-ciocirlan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very valuable article. I've added some comments about explanations and phrasing. Otherwise nice 👍 👍
src/data/articles/compile-time-data-contracts-scala-3/index.mdx
Outdated
Show resolved
Hide resolved
src/data/articles/compile-time-data-contracts-scala-3/index.mdx
Outdated
Show resolved
Hide resolved
src/data/articles/compile-time-data-contracts-scala-3/index.mdx
Outdated
Show resolved
Hide resolved
src/data/articles/compile-time-data-contracts-scala-3/index.mdx
Outdated
Show resolved
Hide resolved
src/data/articles/compile-time-data-contracts-scala-3/index.mdx
Outdated
Show resolved
Hide resolved
src/data/articles/compile-time-data-contracts-scala-3/index.mdx
Outdated
Show resolved
Hide resolved
|
docs: address all PR review comments - alphabetize tags, add headings, convert mermaid diagrams to SVG, fix Scala 3 braces syntax, add external tool links, enhance Spark drift example, standardize formatting |
daniel-ciocirlan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the fixes!
I marked some more blocks to use braces - I know they are compact and look a little better with braceless, but consistency is more valuable and longer code blocks (10+ lines) are much less readable with braceless.
If-then-else is fine 👍
| private inline def summonTypeName[T]: String = constValue["" + T] | ||
|
|
||
| private inline def zip[L <: Tuple, R <: List[String]](labels: L, types: List[String]): List[(String, String)] = | ||
| inline labels match |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curly please
|
|
||
| final case class User(id: Long, email: String, note: Option[String]) | ||
|
|
||
| @main def checkShape(): Unit = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curly please
| ### Inspector 1: Is this a case class? | ||
|
|
||
| ```scala | ||
| def isCaseClass(t: TypeRepr): Boolean = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curly please
| t =:= TypeRepr.of[String] // false | ||
|
|
||
| // 3. Pattern matching: Break it apart | ||
| t match |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curly please
| ### Inspector 2: What are the type arguments? | ||
|
|
||
| ```scala | ||
| def appliedArgs(t: TypeRepr): List[TypeRepr] = t match |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curly please
| ### Inspector 4: Is this a sequence? | ||
|
|
||
| ```scala | ||
| def seqArg(t: TypeRepr): Option[TypeRepr] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curly please
| ```scala | ||
| def mapArgs(t: TypeRepr): Option[(TypeRepr, TypeRepr)] = | ||
| if t <:< TypeRepr.of[Map[?, ?]] then | ||
| appliedArgs(t) match |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curly please
| ### Handling case classes: | ||
|
|
||
| ```scala | ||
| if isCaseClass(t) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curly please
| import scala.deriving.Mirror | ||
|
|
||
| final case class Field(name: String, tpe: String, hasDefault: Boolean = false, isOptional: Boolean = false) | ||
| trait Shape[A]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are a bunch of other blocks, I'll mark them
|
Done, converted all braceless syntax to use braces. |
|
Ready for review. |
docs: Add article compile-time data contracts article with Scala 3 macros and schema validation