aboutsummaryrefslogtreecommitdiff
path: root/src/server/View/Format.hs
blob: 354d46ae2e5aed12e9779879773cd83e59189d22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{-# 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))