Skip to content
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

How does this differ from Map's implementation? #9

Open
marcandre opened this issue Aug 12, 2023 · 1 comment
Open

How does this differ from Map's implementation? #9

marcandre opened this issue Aug 12, 2023 · 1 comment

Comments

@marcandre
Copy link

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?

@turion
Copy link

turion commented Sep 1, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants