Giter Site home page Giter Site logo

unison-money's Introduction

💰unison-money

A Small library for working with Money in Unison

Install

Status: 🏗 Pre-release

This library is currently very much in the development and exploration phase.

Install latest (pre-release):

.> pull https://github.com/hojberg/unison-money:.releases._latest external.money

Design

The design of the library is built after a couple of principles.

  1. We want to ensure Money is handled correctly and that money math is sound. The amount is stored as an Int in "cents" (as a term meaning to any minor part of a currency).
  2. It should not be possible to do any math operations of Money of different currencies. This is done by a type variable in the constructor. Currently any type can be added as a currency, though the library does come with a set of currencies. Typeclasses might help tighting up this API in the future.
  3. Regular division of Money is tough and doesn't quite make sense because you can't have half a penny. Instead we allow splitting Money where whole remainder is added to one of the chunks: 10 split into 3, results in 3 new Money types, 2 where the amount is 3 and 1 where the amount is 4. Note that there are cases where fractional pennies make sense, but that has not been the focus here.

API

  • Money Constructor: Create a Money value with Money USD +499 for an amount representing $ 4.99
  • Money.toText: Simply formats the Money as a Text (in the format of USD 4.99 with any regard for localized formatting (this will be added later): Money.toText : Money a -> Text
  • Money.+ (aliased as plus)
  • Money.- (aliased as minus)
  • Money.* (aliased as multiply)
  • Money.split: Take 1 Money and split into Nat chunks. Returns a list of the possible splits with whole remainders added to the Money values at the end of the list: Money.split 3 (Money USD +10) (10 cents) results in [Money USD +3, Money USD +3, Money USD +4]

Planned API

  • Formatting function that allows localized formatting of Money
  • Percents, for instance for adding 20% tip at a Restaurant.
  • Tax

unison-money's People

Contributors

hojberg avatar

Stargazers

Flavio Corpa avatar Tim Kersey avatar  avatar  avatar Francis De Brabandere avatar

Watchers

 avatar Thor Adam avatar James Cloos avatar

unison-money's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.