{-# LANGUAGE OverloadedStrings #-} module View.Format ( price ) where import Data.Text (Text) import qualified Data.Text as T import Data.List (intersperse) import Conf (Conf) import qualified Conf price :: Conf -> Int -> Text price conf amount = T.concat [number amount, " ", Conf.currency conf] number :: Int -> Text number n = T.pack . (++) (if n < 0 then "-" else "") . reverse . concat . intersperse " " . group 3 . reverse . show . abs $ n group :: Int -> [a] -> [[a]] group n xs = if length xs <= n then [xs] else (take n xs) : (group n (drop n xs))