1 {-# LANGUAGE TupleSections #-}
2 module Hcompta.Tag where
4 import qualified Data.List.NonEmpty as NonEmpty
5 import Data.List.NonEmpty (NonEmpty(..))
6 import Data.Maybe (Maybe(..))
7 import qualified Data.Text as Text
8 import Data.Text (Text)
13 -- | An 'Tag' is a non-empty list of 'Section'.
14 type Tag = (Path, Value)
16 type Path = NonEmpty Section
19 -- | Return the 'Tag' formed by the given 'Path' and 'Value'.
20 tag :: Path -> Value -> Tag
23 -- | Return the 'Value' formed by the given 'Section' and 'Section's.
24 path :: Section -> [Section] -> Path
27 -- | Return the 'Value' of a 'Tag', if any.
28 value :: Tag -> Maybe Value
29 value (_, v) | Text.null v = Nothing
32 -- | Return the number of 'Section's in the given 'Tag'.
34 depth = NonEmpty.length
36 -- | Return an 'Tag' from the given list.
37 from_List :: [Section] -> Path
38 from_List = NonEmpty.fromList