1 {-# LANGUAGE DeriveDataTypeable #-}
2 module Hcompta.Model.Account where
5 import Data.Function (on)
6 import qualified Data.List
7 import qualified Data.Map
9 import Data.Maybe (fromMaybe)
10 import Data.Typeable ()
11 -- import qualified Text.Parsec as P
12 -- import Text.Parsec (Stream, ParsecT, (<|>), (<?>))
14 -- import qualified Hcompta.Model.Account.Path as Path
15 import qualified Hcompta.Model.Amount as Amount
16 import Hcompta.Model.Amount (Amount)
17 import qualified Hcompta.Model.Transaction.Tag as Tag
18 import Hcompta.Model.Transaction.Tag (Tag)
19 import Hcompta.Lib.Regex (Regex)
21 -- * The 'Account' type
29 -- | Return the given 'Account' without its last 'Name' is any.
30 ascending :: Account -> Account
33 ascending (n:a) = n:ascending a
35 -- | Apply the given function to all the prefixes of the given 'Account'.
36 fold :: Account -> (Account -> a -> a) -> a -> a
39 loop :: Account -> Account -> (Account -> a -> a) -> a -> a
40 loop _path [] _f acc = acc
41 loop path (name:account) f acc =
42 let next = (Hcompta.Model.Account.++) path [name] in
43 loop next account f (f next acc)
46 -- | Return the concatenation of the given 'Account'.
47 (++) :: Account -> Account -> Account
57 deriving (Data, Eq, Read, Show, Typeable)
59 -- * The 'Filter' type
62 = Pattern_Exact Account
65 deriving (Read, Show, Typeable)