{-# LANGUAGE DeriveDataTypeable #-} module Hcompta.Model.Account where import Data.Data import Data.Function (on) import qualified Data.List import qualified Data.Map import Data.Map (Map) import Data.Maybe (fromMaybe) import Data.Typeable () -- import qualified Hcompta.Model.Account.Path as Path import qualified Hcompta.Model.Amount as Amount import Hcompta.Model.Amount (Amount) import qualified Hcompta.Model.Transaction.Tag as Tag import Hcompta.Model.Transaction.Tag (Tag) -- * The 'Account' type type Account = [Name] type Name = String nil :: Account nil = [] -- | Apply the given function to all the prefixes of the given 'Account'. fold :: Account -> (Account -> a -> a) -> a -> a fold = loop [] where loop :: Account -> Account -> (Account -> a -> a) -> a -> a loop _path [] _f acc = acc loop path (name:account) f acc = let next = path++[name] in loop next account f (f next acc) -- | Return the given 'Account' without its last 'Name'. chomp :: Account -> Account chomp [] = [] chomp [a] = [] chomp (n:a) = n:chomp a