Scala functional library to deal amounts of money. The goal is to provide basic mathematical reasoning to work in money currency and exchange rate.
See the Documentation website https://fabiopinheiro.github.io/cats-money/
To use the online IDE dondload and install the Visual Studio plugins from the marketplace:
- Scala - https://marketplace.visualstudio.com/items?itemName=scala-lang.scala
- Metals - https://marketplace.visualstudio.com/items?itemName=scalameta.metals
To compile and run you can install scala and sbt: sdk install scala
& sdk install sbt
You will need to have Git, Java 8, and SBT installed.
We try to have a similar structure to the cats library. Have a look of the Cats Infographic from tpolecat and to the Underscore's Scala Book.
You can also start a Scala console from in SBT (scala>
prompt)
to play with small snippets of code:
import cats._, implicits._
import shapeless._, record._, union._, syntax.singleton._
import app.fmgp.money.instances.all._
import app.fmgp.money._
import app.fmgp.money.MoneyY._
import app.fmgp.money.CurrencyY._
Have a look on the to Demos for more examples (on the test folder):
sbt "test:runMain app.fmgp.money.Demo"
sbt "test:runMain app.fmgp.money.Main"
This is still only a draft and experimental library. But I plane to use this on the near future. If anyone else is also looking for a functional approach to work with monetary value, send me a messagem. (I would appreciate example use cases to better reflect over the library.)
The current maintainers (people who can merge pull requests) are:
- implement:
- Traverse[MoneyTree]
- Money comparison of different Currency shound NOT compile
- Try derivation -> https://dotty.epfl.ch/docs/reference/contextual/derivation.html
- Try multiversal-equality -> https://dotty.epfl.ch/docs/reference/contextual/multiversal-equality.html
- Add Documentation
- [WIP] Make a website with https://v2.docusaurus.io/
- Use dotty Importing Givens - https://dotty.epfl.ch/docs/reference/contextual/given-imports.html
- Wirte the Demo using mdoc. (Need to wait for better integration with dotty)
- rename classes and draw a UML
- rename MoneyY and CurrencyY files
- rename MoneyY to Money.
- move all the other Money type to other place (like 'experimental' package)
- currency
- add all currencies from ISO-4217
- create subset type of currencies
- [-] try shapeless Union type
type U = Union.`'a -> EUR, 'b -> USD`.T val u1 = Coproduct[U]('a ->> EUR) println("u1", u1)
- try Dotty Union Types =)
- [-] try shapeless Union type
- implement the rates conversion on a subset of currencies
- [-] try shapeless polymorphic function
object polymorphicF extends Poly1 { implicit def caseEUR = at[EUR.type](i => "sEUR") implicit def caseSUSD = at[USD.type](s => "sUSD") } type CU = EUR.type :+: USD.type :+: CNil val cu = Coproduct[CU](USD) println("cu", cu, cu map polymorphicF)
- [-] try shapeless polymorphic function
- tests:
- Testing for non-compilation of type unsafe
- Add a code coverage tool (sbt-scoverage)
- demo:
- [WIP] (+- Done) Demo Main
- to try:
- Epimorphism, Monomorphism and Isomorphism
- Rings +-
cats-money is licensed under the MIT license, available at http://opensource.org/licenses/mit-license.php and also in the LICENSE file.
Copyright the Fabio Pinheiro, 2020.