accessible icon indicating copy to clipboard operation
accessible copied to clipboard

How does this differ from Map's implementation?

Open marcandre opened this issue 2 years ago • 1 comments

I was looking for exactly that, but I wish the doc explained why the implementation is more complex than expected and why we shouldn't simply use defdelegate to Map, as in #5?

marcandre avatar Aug 12 '23 20:08 marcandre

I can only speculate. Let's have a look at put:

      def put(struct, key, val) do
        if Map.has_key?(struct, key) do
          Map.put(struct, key, val)
        else
          struct
        end
      end

This is nearly Map.put, but doesn't put a value if it is not declared in the struct. Which makes some sense, because you'd want the struct to keep its structure, and not have additional ad-hoc keys. One can argue whether it should silently discard (as is done here) or throw an exception, and I agree that such a choice should be documented.

turion avatar Sep 01 '23 13:09 turion