Implication of polymorphic Amount to round-trip conversions
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 58
- Forks
- 12
- Avg merge
- 2h 35m
- Merged PRs (30d)
- 2
Description
The current Amount proposal allows code such as
let amt1 = new Amount(2.5, { unit: "meter" });
let amt2 = amt1.withNumber(amt1.toNumber() * 2);
Without the helper functions withNumber and toNumber, the code is still possible, though a bit more verbose, perhaps worth moving into a helper function:
function doubleAmount(amt) {
let number = Number.parseFloat(amt.toString());
return new Amount(number * 2, { unit: amt.unit });
}
A concern here is that if developers are encouraged to use such a pattern, the resulting code is less efficient than if they had not converted to an Amount, if the Amount is stored as a decimal-like type.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with issue #72 and the current Amount proposal, focusing on the withNumber(), toNumber(), and helper-function examples. Determine whether round-trip conversions should be part of the proposal or avoided for efficiency when Amount uses a decimal-like representation. Done means the conversion concern has a documented design decision.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100