Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map -spec in erlang

I'm looking to use the new erlang maps in a project, but I want to make sure to properly -spec everything I do. So my question is, what's the syntax for this? Is there anything like there is for records where I can specify field types? Or do I just use map() (and is that even the correct type spec?)

like image 506
Mediocre Gopher Avatar asked Jul 26 '26 01:07

Mediocre Gopher


1 Answers

Yes, map() is one way to specify a map type. Another is #{}, which like map() means a map of any size. You can also specify #{ Type => Type } with one or more Type => Type pairs, as described in the Erlang Types and Function Specifications page. Also, have a look at the can_pkt() type in the source code for the maps1 test in the Erlang source code, as that specifies a record-like map type.

like image 77
Steve Vinoski Avatar answered Jul 28 '26 16:07

Steve Vinoski