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 ()
12 -- import qualified Hcompta.Model.Account.Path as Path
13 import qualified Hcompta.Model.Amount as Amount
14 import Hcompta.Model.Amount (Amount)
15 import qualified Hcompta.Model.Transaction.Tag as Tag
16 import Hcompta.Model.Transaction.Tag (Tag)
18 -- * The 'Account' type
26 -- | Return the given 'Account' without its last 'Name' is any.
27 ascending :: Account -> Account
30 ascending (n:a) = n:ascending a
32 -- | Apply the given function to all the prefixes of the given 'Account'.
33 fold :: Account -> (Account -> a -> a) -> a -> a
36 loop :: Account -> Account -> (Account -> a -> a) -> a -> a
37 loop _path [] _f acc = acc
38 loop path (name:account) f acc =
39 let next = path++[name] in
40 loop next account f (f next acc)