Skip to content

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

Open

Description

@marcandre

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?

Activity

  1. turion commented on Sep 1, 2023

    @turion

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions