1 {-# LANGUAGE DeriveDataTypeable #-}
2 module Hcompta.Model.Account where
4 import Data.Data (Data)
5 import qualified Data.List
6 import Data.Typeable (Typeable)
7 -- import qualified Text.Parsec as P
8 -- import Text.Parsec (Stream, ParsecT, (<|>), (<?>))
9 import Data.Text (Text)
11 -- import qualified Hcompta.Model.Account.Path as Path
12 import Hcompta.Lib.Regex (Regex)
14 -- * The 'Account' type
17 type Name = Text -- TODO: use Text?
22 -- | Return the given 'Account' without its last 'Name' is any.
23 ascending :: Account -> Account
26 ascending (n:a) = n:ascending a
28 -- | Apply the given function to all the prefixes of the given 'Account'.
29 fold :: Account -> (Account -> a -> a) -> a -> a
32 loop :: Account -> Account -> (Account -> a -> a) -> a -> a
33 loop _path [] _f acc = acc
34 loop path (name:account) f acc =
35 let next = (Hcompta.Model.Account.++) path [name] in
36 loop next account f (f next acc)
39 -- | Return the concatenation of the given 'Account'.
40 (++) :: Account -> Account -> Account
50 deriving (Data, Eq, Read, Show, Typeable)
52 -- * The 'Filter' type
55 = Pattern_Exact Account
58 deriving (Read, Show, Typeable)