Skip to content

Instantly share code, notes, and snippets.

@beccadax
Last active April 29, 2017 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beccadax/daa9e2112f9c6aa4a5720cf5e81febb6 to your computer and use it in GitHub Desktop.
Save beccadax/daa9e2112f9c6aa4a5720cf5e81febb6 to your computer and use it in GitHub Desktop.
print("""
<?xml version="1.0"?>
<catalog>
\(bookTuples.map(xmlForBookTuple).joined(separator: "")
)</catalog>
""")
typealias ChapterTuple = (heading: String)
typealias BookTuple = (id: String, author: String, title: String, genre: String, price: String, chapters: [ChapterTuple])
func xmlForChapterTuple(_ c: ChapterTuple) -> String {
return """
<heading>\(heading)</heading>
"""
}
func xmlForBookTuple(_ b: BookTuple) -> String {
return """
<book id="bk\(b.id)" empty="">
<author>\(b.author)</author>
<title>\(b.title)</title>
<genre>\(b.genre)</genre>
<price>\(b.price)</price>
<chapters>
\(b.chapters.map(xmlForChapterTuple).joined(separator: "")
) </chapters>
</book>
"""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment