I think we should encourage pure functional use of this library. For example:
# Prefer this
total = Cents.percent(Cents.sum(10, 25), 0.5, transform: 'round')
# Over this
total = new Cents(10).plus(new Cents(25)).percent(0.5, transform: 'round').toNumber()
We commonly serialize and deserialize cents values as numbers. I believe the interfaces between modules should be defined in terms of Numbers, not Cents objects, so that dependencies are explicit and so that individual modules can choose more appropriate libraries (like higher precision or big number) as needed.
In that world, new Cents() and .toNumber() are boilerplate to write and a small performance overhead.
I think we should encourage pure functional use of this library. For example:
We commonly serialize and deserialize cents values as numbers. I believe the interfaces between modules should be defined in terms of Numbers, not Cents objects, so that dependencies are explicit and so that individual modules can choose more appropriate libraries (like higher precision or big number) as needed.
In that world,
new Cents()
and.toNumber()
are boilerplate to write and a small performance overhead.