haspara-0.0.0.0: A library providing definitions to work with monetary values.
Safe HaskellNone
LanguageHaskell2010

Haspara.Internal.Currency

Description

This module provides internal definitions for modeling and working with currencies.

Synopsis

Data Definition

newtype Currency Source #

Type encoding for currencies.

Constructors

MkCurrency 

Fields

Instances

Instances details
Eq Currency Source # 
Instance details

Defined in Haspara.Internal.Currency

Ord Currency Source # 
Instance details

Defined in Haspara.Internal.Currency

Show Currency Source #

Show instance for Currency.

>>> MkCurrency "USD"
USD
Instance details

Defined in Haspara.Internal.Currency

IsString Currency Source #

IsString instance for Currency.

>>> "USD" :: Currency
USD
Instance details

Defined in Haspara.Internal.Currency

Hashable Currency Source # 
Instance details

Defined in Haspara.Internal.Currency

Methods

hashWithSalt :: Int -> Currency -> Int #

hash :: Currency -> Int #

ToJSON Currency Source #

ToJSON instance for Currency.

>>> Aeson.encode (MkCurrency "USD")
"\"USD\""
Instance details

Defined in Haspara.Internal.Currency

FromJSON Currency Source #

FromJSON instance for Currency.

>>> Aeson.eitherDecode "\"\"" :: Either String Currency
Left "Error in $: Currency code error! Expecting at least 3 uppercase characters, but received: \"\""
>>> Aeson.eitherDecode "\"ABC\"" :: Either String Currency
Right ABC
Instance details

Defined in Haspara.Internal.Currency

Lift Currency Source # 
Instance details

Defined in Haspara.Internal.Currency

Constructors

currency :: MonadError String m => Text -> m Currency Source #

Smart constructor for Currency values within MonadError context.

>>> currency "" :: Either String Currency
Left "Currency code error! Expecting at least 3 uppercase characters, but received: \"\""
>>> currency " " :: Either String Currency
Left "Currency code error! Expecting at least 3 uppercase characters, but received: \" \""
>>> currency "AB" :: Either String Currency
Left "Currency code error! Expecting at least 3 uppercase characters, but received: \"AB\""
>>> currency " ABC " :: Either String Currency
Left "Currency code error! Expecting at least 3 uppercase characters, but received: \" ABC \""
>>> currency "ABC" :: Either String Currency
Right ABC

currencyFail :: MonadFail m => Text -> m Currency Source #

Smart constructor for Currency values within MonadFail context.

>>> currencyFail "" :: Maybe Currency
Nothing
>>> currencyFail "US" :: Maybe Currency
Nothing
>>> currencyFail "usd" :: Maybe Currency
Nothing
>>> currencyFail "USD" :: Maybe Currency
Just USD

Auxiliaries

currencyCodeParser :: Parsec Void Text Text Source #

Parser that parses currency codes.

>>> MP.runParser currencyCodeParser "Example" ""
Left (ParseErrorBundle {bundleErrors = TrivialError 0 (Just EndOfInput) (fromList []) :| [], bundlePosState = PosState {pstateInput = "", pstateOffset = 0, pstateSourcePos = SourcePos {sourceName = "Example", sourceLine = Pos 1, sourceColumn = Pos 1}, pstateTabWidth = Pos 8, pstateLinePrefix = ""}})
>>> MP.runParser currencyCodeParser "Example" " "
Left (ParseErrorBundle {bundleErrors = TrivialError 0 (Just (Tokens (' ' :| ""))) (fromList []) :| [], bundlePosState = PosState {pstateInput = " ", pstateOffset = 0, pstateSourcePos = SourcePos {sourceName = "Example", sourceLine = Pos 1, sourceColumn = Pos 1}, pstateTabWidth = Pos 8, pstateLinePrefix = ""}})
>>> MP.runParser currencyCodeParser "Example" "a"
Left (ParseErrorBundle {bundleErrors = TrivialError 0 (Just (Tokens ('a' :| ""))) (fromList []) :| [], bundlePosState = PosState {pstateInput = "a", pstateOffset = 0, pstateSourcePos = SourcePos {sourceName = "Example", sourceLine = Pos 1, sourceColumn = Pos 1}, pstateTabWidth = Pos 8, pstateLinePrefix = ""}})
>>> MP.runParser currencyCodeParser "Example" "A"
Left (ParseErrorBundle {bundleErrors = TrivialError 1 (Just EndOfInput) (fromList []) :| [], bundlePosState = PosState {pstateInput = "A", pstateOffset = 0, pstateSourcePos = SourcePos {sourceName = "Example", sourceLine = Pos 1, sourceColumn = Pos 1}, pstateTabWidth = Pos 8, pstateLinePrefix = ""}})
>>> MP.runParser currencyCodeParser "Example" "AB"
Left (ParseErrorBundle {bundleErrors = TrivialError 2 (Just EndOfInput) (fromList []) :| [], bundlePosState = PosState {pstateInput = "AB", pstateOffset = 0, pstateSourcePos = SourcePos {sourceName = "Example", sourceLine = Pos 1, sourceColumn = Pos 1}, pstateTabWidth = Pos 8, pstateLinePrefix = ""}})
>>> MP.runParser currencyCodeParser "Example" "ABC"
Right "ABC"