Last active
April 29, 2017 12:30
-
-
Save beccadax/daa9e2112f9c6aa4a5720cf5e81febb6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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