1 {-# LANGUAGE TupleSections #-}
2 module Hcompta.Tag where
4 import qualified Data.List.NonEmpty as NonEmpty
5 import Data.List.NonEmpty (NonEmpty(..))
6 import qualified Data.Text as Text
7 import Data.Text (Text)
11 -- | An 'Tag' is a non-empty list of 'Section'.
12 type Tag = (Path, Value)
14 type Path = NonEmpty Section
17 -- | Return the 'Tag' formed by the given 'Path' and 'Value'.
18 tag :: Path -> Value -> Tag
21 -- | Return the 'Value' formed by the given 'Section' and 'Section's.
22 path :: Section -> [Section] -> Path
25 -- | Return the 'Value' of a 'Tag', if any.
26 value :: Tag -> Maybe Value
27 value (_, v) | Text.null v = Nothing
30 -- | Return the number of 'Section's in the given 'Tag'.
32 depth = NonEmpty.length
34 -- | Return an 'Tag' from the given list.
35 from_List :: [Section] -> Path
36 from_List = NonEmpty.fromList