scala - Best practice for modifying collection attributes functionally -
I'm curious about how to implement a class that adheres to strict functional programming rules.
For example, if I have a class in which there are two characteristics and I have a way that modifies them, how would I do this? The characteristics will be private vals, and the method will have to return a new instance of the attribute whenever it modifies it. It's okay, except I would like to keep it in vogue, that is, I need a way to set the value.
What would be the best way to do this so that I do not have thousands of examples, a collection, floating in memory?
This is my opinion, but; As classes of classes do, I will apply a code to the copy
method to make amendments possible to maintain irreversible, but in some cases I can help to destabilize it. can not do ; For example, when something is expected that the copy operation is too big and slow for the classroom; Like when there are frequent revised members in the class and do not worry about thousands of instances running around in memory, because they have been automatically acquired, hence the real problem is the time cost of copying class examples is. Please tell me that my opinion is wrong in some way :)
Comments
Post a Comment