Skip to content

Conversation

@sabiwara
Copy link
Contributor

@sabiwara sabiwara commented May 4, 2024

Implemented based on is_struct/1.

The second commit adds an admonition to is_map/1 to increase awareness:
Screenshot 2024-05-04 at 9 39 38

Copy link
Member

@whatyouhide whatyouhide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no second commit 🙃

end

@doc """
Returns `true` if `term` is a non-struct map; otherwise returns `false`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Returns `true` if `term` is a non-struct map; otherwise returns `false`.
Returns `true` if `term` is a non-struct map, otherwise returns `false`.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another idea is: Returns true if term is a map that is not a struct (…)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sabiwara sabiwara force-pushed the is_non_struct_map branch from f88eda4 to 3c0fb46 Compare May 4, 2024 09:08
@sabiwara
Copy link
Contributor Author

sabiwara commented May 4, 2024

There is no second commit 🙃

😅 Pushed 3c0fb46

@michallepicki
Copy link
Contributor

Today this can be achieved with is_map(x) and not is_struct(x), right?

@sabiwara
Copy link
Contributor Author

sabiwara commented May 4, 2024

Today this can be achieved with is_map(x) and not is_struct(x), right?

Correct, this is how you have to achieve it right now.
The idea is to lower the barrier to do the safer thing by having a built-in guard in the language, and spread awareness about the gotcha described in point 4 here.

Co-authored-by: José Valim <jose.valim@gmail.com>
> #### Structs are maps {: .info}
>
> Structs are also maps, and many of Elixir data structures are implemented
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> Structs are also maps, and many of Elixir data structures are implemented
> Structs are also maps, and many of Elixir's data structures are implemented

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vanderhoop I quickly grepped the codebase and seems we've been using Elixir data structures in other places so will keep the consistency (or we should fix it elsewhere too). Thank you!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 🚀

@sabiwara sabiwara merged commit 27164e3 into elixir-lang:main May 4, 2024
@sabiwara sabiwara deleted the is_non_struct_map branch May 4, 2024 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

6 participants