Skip to content

Commit

Permalink
Use Scala 3-5-style Showable typeclass instead of Show
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Jun 12, 2024
1 parent 7553137 commit a0302fd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/core/xmlast.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ import gossamer.*
import spectacular.*

object XmlAst:
given Show[XmlAst] =
given XmlAst is Showable =
case Comment(content) => t"<!--$content-->"
case ProcessingInstruction(target, content) => t"<?$target $content?>"
case Textual(content) => content
case CData(content) => t"<![CDATA[$content]]>"
case Root(content*) => t"""<?xml version = "1.0"?>${content.map(_.show).join}"""

case Element(name, children, attributes, _) =>
val inside = children.map(_.show).join
val attributeString = attributes.map { case (k, v) => t"${k.show}=$v" }.join(t" ", t" ", t"")

t"<${name.show}${attributeString}>$inside</${name.show}>"

enum XmlAst:
Expand Down
4 changes: 2 additions & 2 deletions src/core/xylophone.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import scala.util.NotGiven
case class Namespace(id: Text, uri: Text)

object XmlName:
given Show[XmlName] = name => name.namespace match
given XmlName is Showable = name => name.namespace match
case Unset => name.name
case Namespace(prefix, _) => t"$prefix:${name.name}"

Expand All @@ -50,7 +50,7 @@ sealed trait Xml:
type XmlPath = List[Text | Int | Unit]

object Xml:
given show: Show[Xml] = xml =>
given Xml is Showable = xml =>
safely(printers.compact.print(XmlDoc(XmlAst.Root(Xml.normalize(xml)*)))).or(t"undefined")

given (using enc: Encoding, printer: XmlPrinter[Text]) => Xml is GenericHttpResponseStream:
Expand Down

0 comments on commit a0302fd

Please sign in to comment.