(.module: [library [lux #* [abstract [equivalence (#+ Equivalence)] [monad (#+ do)]] [control ["." exception (#+ exception:)] ["<>" parser ["<.>" xml (#+ Parser)] ["<.>" text]]] [data ["." product] ["." text ["%" format]] [format ["." xml (#+ XML)]] [collection ["." list ("#\." functor)]]] [math [number ["n" nat]]] ["." time (#+ Time) ["." date (#+ Date)] ["." year] ["." month]]]] ["." // #_ ["#." time] ["#." snapshot (#+ Snapshot) ["#/." version (#+ Version)]]]) (type: .public Versioning {#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 (^slots [#snapshot #last_updated #versions])) (-> 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)) )))