(.using [library [lux "*" [abstract [equivalence {"+" Equivalence}] [monad {"+" do}]] [control ["[0]" exception {"+" exception:}] ["<>" parser ["<[0]>" xml {"+" Parser}] ["<[0]>" text]]] [data ["[0]" product] ["[0]" text ["%" format]] [format ["[0]" xml {"+" XML}]] [collection ["[0]" list ("[1]#[0]" functor)]]] [math [number ["n" nat]]] ["[0]" time {"+" Time} ["[0]" date {"+" Date}] ["[0]" year] ["[0]" month]]]] ["[0]" // "_" ["[1][0]" time] ["[1][0]" snapshot {"+" Snapshot} ["[1]/[0]" version {"+" Version}]]]) (type: .public Versioning (Record [#snapshot Snapshot #last_updated //time.Time #versions (List Version)])) (def: .public init [#snapshot {//snapshot.#Local} #last_updated //time.epoch #versions (list)]) (def: .public equivalence (Equivalence Versioning) ($_ product.equivalence //snapshot.equivalence //time.equivalence (list.equivalence //snapshot/version.equivalence) )) (template [ ] [(def: xml.Tag ["" ])] [ "lastUpdated"] [ "snapshotVersions"] [ "versioning"] ) (def: last_updated_format (-> //time.Time XML) (|>> //time.format {xml.#Text} list {xml.#Node .. xml.attributes})) (def: .public (format (open "_[0]")) (-> Versioning XML) (<| {xml.#Node .. xml.attributes} (list (//snapshot.format _#snapshot) (..last_updated_format _#last_updated) (|> _#versions (list#each //snapshot/version.format) {xml.#Node .. xml.attributes})))) (def: (text tag) (-> xml.Tag (Parser Text)) (<| (.node tag) .text)) (def: last_updated_parser (Parser //time.Time) (<| (.then //time.parser) (..text ..))) (def: .public parser (Parser Versioning) (<| (.node ..) ($_ <>.and (<>.else {//snapshot.#Local} (.somewhere //snapshot.parser)) (<>.else //time.epoch (.somewhere ..last_updated_parser)) (<| (<>.else (list)) .somewhere (.node ..) (<>.some //snapshot/version.parser)) )))