The currency-codes package

[ Tags: data, library, mit ] [ Propose Tags ]

ISO-4217 Currency Codes


[Skip to Readme]

Properties

Versions 1.0.0.0, 1.0.0.1, 1.0.0.2, 1.0.0.3, 2.0.0.0 (info)
Change log CHANGELOG.md
Dependencies aeson (>=0.7.0.0), base (==4.*), bson (>=0.2.0), random (>=1.0.0.0), safe (>=0.2), text (>=1.0.0.0) [details]
License MIT
Copyright (c) 2017 Chordify
Author Chordify
Maintainer Matthias Benkort <matthias@chordify.net>
Category Data
Home page https://github.com/chordify/currency-codes
Bug tracker https://github.com/chordify/currency-codes/issues
Uploaded Tue Sep 19 08:13:31 UTC 2017 by KtorZ
Distributions
Downloads 61 total (61 in the last 30 days)
Rating 0.0 (0 ratings) [clear rating]
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-09-19 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for currency-codes-2.0.0.0

[back to package description]

Currency Codes (ISO-4217)

Overview

This package mainly provides 2 data types to represent and manipulate currencies according to the ISO 4217 standard.

It also provides a handful of instances for common typeclasses (Show, Read, Random, ToJSON, FromJSON, Val, ToSchema).

Example

import           Data.Aeson     (ToJSON(..))
import qualified Data.Aeson     as Aeson
import           Data.Currency  (Currency, Alpha)
import qualified Data.Currency  as Currency
import           GHC.Generics   (Generic)
import qualified Safe


myCurrencies :: [Currency]
myCurrencies =
  [Currency.eur, Currency.usdDollar]

fromAlpha :: Alpha -> [Currency] -> Maybe Currency
fromAlpha α =
  Safe.headMay . filter ((==) α . Currency.alpha)


data Transaction = Transaction
  { amount   :: Integer
  , currency :: Currency
  } deriving (Eq, Show, Generic)

instance ToJSON Transaction where
  toJSON = 
    Aeson.genericToJSON Aeson.defaultOptions

License

MIT © 2017 Chordify