MapSet in typespecs

If there a way to specify a MapSet with keys of a certain type?
Something like: @type a :: %MapSet{integer}

I can’t find anything in the docs.

1 Like

MapSet has a section called types in its documentation.

There you find the following three types:

  • t() :: t(term)
  • t(value)
  • value() :: term

Since t/x is the idiomatic way to write the modules main type, the type you are searching for is probably t/1:

@type a :: MapSet.t(integer)

Thanks, I was confused by the lack of an example typespec. Maybe someone should add an example to the docs?

There are quite a couple of them. Let me show you right the first:

@spec delete(t(val1), val2) :: t(val1) when val1: value, val2: value

Though these examples are local-types not remote-types.

This spec means that when you have a Set which elements are of type val1 and another value of any type, the function will return a set which elements are still of the same type as before.

1 Like

Yes, I understand now, I just didn’t make the connection that you could use MapSet.t(value) in your own code :slight_smile: Sorry for the stupid question.

Stupid questions are those that don’t get asked, so please feel free to ask questions as they arise.