You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In some cases where using the current syntax I'd like to optionally apply negation of absolute values to something without having to break out of the current builder syntax. For example:
The idea here is that I only sometimes want to negate the value (in my arbitrary example, if it's even). In addition to closures, it would be nice if this could take bools as well if higher up the stack we are doing a bit of logic that will decide if it should be negated. This would also be useful in abs() as well where sometimes we don't necessarily want to return the absolute value.
My goal for this would be to bring this into brick/money after this gets approved as I find myself most often requiring these helpers when dealing with transforming dual-entry accounting that our finance system runs in into something more user friendly when showing a balance.
Approach
I'll write a PR for this. My approach would be to create a helper to satisfy if the passed value should resolve. In quick pseudo-code this would look like:
And this would be applied out to each class...Decimal, Rational, etc etc. If we're happy with this feature I will write a PR here and for the brick/money library as well
The text was updated successfully, but these errors were encountered:
Unfortunately I don't think this feature is a good fit for brick/math in its current form: IMO it complicates the API and increases the cognitive load for other users, for a use case that I would consider niche. Plus, if we were to implement this, I think it would be inconsistent to only apply it to abs() and negated(): it could very well be applied to all operations, including plus(), minus() etc.
I do understand where you're coming from though, and in your specific use case, this API does make the code a bit more readable.
One solution could be to create your own BigInteger class that wraps brick/math's BigInteger, and add your own methods there.
Another solution would be to add a single generic method, like apply(), that would take a Closure which accepts and returns a BigNumber, allowing to modify the current number without leaving the fluent API:
Use case
In some cases where using the current syntax I'd like to optionally apply negation of absolute values to something without having to break out of the current builder syntax. For example:
The alternative to this is a little more cumbersome with:
The idea here is that I only sometimes want to negate the value (in my arbitrary example, if it's even). In addition to closures, it would be nice if this could take bools as well if higher up the stack we are doing a bit of logic that will decide if it should be negated. This would also be useful in
abs()
as well where sometimes we don't necessarily want to return the absolute value.My goal for this would be to bring this into brick/money after this gets approved as I find myself most often requiring these helpers when dealing with transforming dual-entry accounting that our finance system runs in into something more user friendly when showing a balance.
Approach
I'll write a PR for this. My approach would be to create a helper to satisfy if the passed value should resolve. In quick pseudo-code this would look like:
And this would be applied out to each class...Decimal, Rational, etc etc. If we're happy with this feature I will write a PR here and for the brick/money library as well
The text was updated successfully, but these errors were encountered: