-
Notifications
You must be signed in to change notification settings - Fork 16
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
All imutable data structures also need a subtraction operations #2
Comments
Can be done via destructuring and ES object rest/spread:
|
That doesn't allow you to remove something where you don't know the key ahead of time though. Though maybe you could use computed property names?
That's a lot more wonky than something this though:
|
I have perhaps a more radical idea. What about operator overloading? +
This could be contentious, as the add operation is not commutative:
But I think this is not a big deal. As Other operators, such as subtractions and division are not commutative anyway. - Subtraction:
I don't see any obvious use for the multiplication or division operators. Would love for you to just think about it. It's possibly a very bad idea. |
@nmn That could work together with Value Objects I guess. |
After looking at some other ES7 proposals, it turns out that associative functions can be important. Specially for parallel operations. So I think we're in a good place if we can support associative operators, even if they are not commutative. The + and - operators are both associative above. (I'll write a maths proof if that's needed) A possible way around would be to define the addition operation differently, and more like matrix addition. This would add the values of the same keys together. This would be a more correct way to do addition. But it would also be less useful due to typecasting. |
Perhaps this could be best suited as some kind of function, a la Note: I'm also not opposed having a literal syntax that is equivalent to this. We could simply hijack the const point3d = #{ x: 1, y: 2, z: 3};
const point2d = delete point3d.z;
|
From what I can tell all the proposed types have extension operations defined but non of them have a subtraction, maybe syntax could be borrowed from elm ?
The text was updated successfully, but these errors were encountered: