Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encourage functional use #1

Open
hurrymaplelad opened this issue Oct 30, 2015 · 0 comments
Open

Encourage functional use #1

hurrymaplelad opened this issue Oct 30, 2015 · 0 comments

Comments

@hurrymaplelad
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant