Created
October 27, 2016 10:31
-
-
Save chriseidhof/b0fb6b0a4cf370e873dc56ee0a6ad42d 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
enum Block { | |
case code(code: String) | |
case text(String) | |
case header(String) | |
} | |
enum PlaygroundElement { | |
case code(String) | |
case documentation([Block]) | |
} | |
func playground(blocks: [Block]) -> [PlaygroundElement] { | |
// We want to generate a playground from an array of `Block` elements. | |
// | |
// Separate the code from the documentation. | |
// All the consecutive non-code should be grouped together. | |
} | |
// The following input: | |
let sample: [Block] = [.code("swift sample code"), .header("My Header"), .text("Hello"), .code("more"), .text("text")] | |
// Should return the following result: | |
let result: [PlaygroundElement] = [ | |
.code("swift sample code"), | |
.documentation[.header("My Header"), .text("Hello")] | |
.code("more"), | |
.documentation[.text("text")] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using indirectEnums and also without mutating the original structs