-
Notifications
You must be signed in to change notification settings - Fork 11.3k
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
[10.x] Add a new Numberable
helper
#49036
Conversation
Building on laravel#48845, this class will work similarly to the `Stringable` class, but for numbers.
ffed3a9
to
f44217a
Compare
I'm making so that these helpers modify the underlying value, instead of creating new instances like in the Stringable class. This is because I think modifying the values is more helpful for the kinds of use cases I see for this feature.
926fcf0
to
68711a5
Compare
Based on laravel@d41e885, instead of the newer laravel@a75dea9 as there are no facade methods where the latter functionality adds value to this case.
68711a5
to
898bc6c
Compare
Would be a great addition, but wouldn't it be better to make this class immutable like the stringable class? |
Thanks for the feedback! It definitely could be, but I went this route because I personally think modifying the values is more helpful for the kinds of use cases I see for this feature being used. But I am 100% open to changing it to be immutable if that turns out to be the consensus on what's best. |
This makes every equation like I would never use this, unless there's actually logic inside that would be worth abstractifying like vector or matrix math. |
That's a great point, and a strong reason to use immutable versions. I'll make a patch tomorrow. Thanks for the feedback! |
I'm not sure about this PR. Your previous PR is great for converting unit of measurement or making numeric values readable, but not for manipulating it. @bert-w's comments is a strong concern. Unless you provide another abstraction for working with arithmetics, I don't really see a good thing why this PR is necessary. |
Good points as well! Thanks for all the feedback! Going to try to refine this tomorrow, then open up for review to see what the team thinks. I appreciate your thoughts! |
🤝 Sincere and humble question, Did you evaluate the possibility to use Money/Money? - This lib is battle tested and offer this functionality out of the box. |
I haven't considered it for this feature, as I think these helpers are best used for quick formatting. If one needs something more robust, I think that's when you would reach for a library like yours. In my opinion, specialised code like that does not need to be in the Laravel core as we have packages to get the functionality when needed. |
Consensus reached in the pull request: laravel#49036 It also removes the tappability as that loses it's functionality when immutable.
I don't really think this is necessary yet. It's common to chain many string operations together when working with strings - I don't think the same is really the case with numbers. |
Fair enough! It was requested by some people after my last PR, and it was fairly quick to make this one so I thought I'd throw it out there in case anyone finds it useful. Thanks for taking the time to review it! |
Abstract
Building on #48845, this class will work similarly to the
Stringable
class, but for numbers.This was requested on the Discord and by several people on Twitter, and mentioned in #48849
Development
Feedback and contributions are much appreciated! I can be reached here, or in the
#internals
Discord.Number
classNumber::of()
andnumber()
shorthands