]> Git — Sourcephile - comptalang.git/blob - lib/Hcompta/Model/Account.hs
Ajout : Format.Ledger.Read : account, amount
[comptalang.git] / lib / Hcompta / Model / Account.hs
1 {-# LANGUAGE DeriveDataTypeable #-}
2 module Hcompta.Model.Account where
3
4 import Data.Data
5 import Data.Function (on)
6 import qualified Data.List
7 import qualified Data.Map
8 import Data.Map (Map)
9 import Data.Maybe (fromMaybe)
10 import Data.Typeable ()
11
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)
17
18 -- * The 'Account' type
19
20 type Account = [Name]
21 type Name = String
22
23 nil :: Account
24 nil = []
25
26 -- | Return the given 'Account' without its last 'Name' is any.
27 ascending :: Account -> Account
28 ascending [] = []
29 ascending [a] = []
30 ascending (n:a) = n:ascending a
31
32 -- | Apply the given function to all the prefixes of the given 'Account'.
33 fold :: Account -> (Account -> a -> a) -> a -> a
34 fold = loop []
35 where
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)