{-# LANGUAGE TupleSections #-} module Hcompta.Tag where import qualified Data.List.NonEmpty as NonEmpty import Data.List.NonEmpty (NonEmpty(..)) import Data.Maybe (Maybe(..)) import qualified Data.Text as Text import Data.Text (Text) import Prelude (Int) -- * The 'Tag' type -- | An 'Tag' is a non-empty list of 'Section'. type Tag = (Path, Value) type Section = Text type Path = NonEmpty Section type Value = Text -- | Return the 'Tag' formed by the given 'Path' and 'Value'. tag :: Path -> Value -> Tag tag = (,) -- | Return the 'Value' formed by the given 'Section' and 'Section's. path :: Section -> [Section] -> Path path = (:|) -- | Return the 'Value' of a 'Tag', if any. value :: Tag -> Maybe Value value (_, v) | Text.null v = Nothing value (_, v) = Just v -- | Return the number of 'Section's in the given 'Tag'. depth :: Path -> Int depth = NonEmpty.length -- | Return an 'Tag' from the given list. from_List :: [Section] -> Path from_List = NonEmpty.fromList