Add a is_mapset/1 function to Kernel

40 views
Skip to first unread message

Debbie

unread,
Jul 30, 2019, 1:49:31 PM7/30/19
to elixir-lang-core
Hi,
today I needed to assert in a test that something was a mapset. I looked for a is_mapset/1 but I couldnt find one. So I created this one for my test:

def is_mapset(%MapSet{}), do: true
def is_mapset(_), do: false

I was kinda surpised that there is no such function because there are similar functions for all other data types afaik.

Thanks for reading

José Valim

unread,
Jul 30, 2019, 1:54:34 PM7/30/19
to elixir-l...@googlegroups.com
All of the “is_” macros can be used in guards and until Erlang/OTP 21 it was not possible to implement said functionality in a way that is guards compatible. We will drop support for OTP 20 once 1.10 is out (in January) so the proposed feature will exist in Elixir v1.11.
--


José Valim
Skype: jv.ptec
Founder and Director of R&D

José Valim

unread,
Jul 30, 2019, 1:55:43 PM7/30/19
to elixir-l...@googlegroups.com
Or to be more precise, we will add is_struct/2, which is a more general feature than the one asked here. There is already an issue tracking this.

Thanks for the proposal!

Norbert Melzer

unread,
Jul 30, 2019, 2:00:10 PM7/30/19
to elixir-lang-core
Due to the opaqueness of `MapSet.t/*` such a macro isn't possible to implement without dialyzer complaining on its usage.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4J8xFB6wHQ4ayNTQF5grJ1N3wzne%2BaW7Sk6Kcn30%2BO5qg%40mail.gmail.com.

José Valim

unread,
Jul 30, 2019, 2:09:41 PM7/30/19
to elixir-l...@googlegroups.com
Yes, we had debates about it and it is not the only time Dialyzer would complain. I believe simply pattern matching on %MapSet{} would generate warnings too. The one who has to change here is dialyzer (or Elixir's interface to dialyzer should provide reasonable alternatives for this - although I have no idea which ones).



José Valim
Skype: jv.ptec
Founder and Director of R&D

Reply all
Reply to author
Forward
0 new messages