
- Erlang Tutorial
- Erlang - Home
- Erlang - Overview
- Erlang - Environment
- Erlang - Basic Syntax
- Erlang - Shell
- Erlang - Data Types
- Erlang - Variables
- Erlang - Operators
- Erlang - Loops
- Erlang - Decision Making
- Erlang - Functions
- Erlang - Modules
- Erlang - Recursion
- Erlang - Numbers
- Erlang - Strings
- Erlang - Lists
- Erlang - File I/O
- Erlang - Atoms
- Erlang - Maps
- Erlang - Tuples
- Erlang - Records
- Erlang - Exceptions
- Erlang - Macros
- Erlang - Header Files
- Erlang - Preprocessors
- Erlang - Pattern Matching
- Erlang - Guards
- Erlang - BIFS
- Erlang - Binaries
- Erlang - Funs
- Erlang - Processes
- Erlang - Emails
- Erlang - Databases
- Erlang - Ports
- Erlang - Distributed Programming
- Erlang - OTP
- Erlang - Concurrency
- Erlang - Performance
- Erlang - Drivers
- Erlang - Web Programming
- Erlang Useful Resources
- Erlang - Quick Guide
- Erlang - Useful Resources
- Erlang - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Erlang - Maps
A map is a compound data type with a variable number of key-value associations. Each key-value association in the map is called an association pair. The key and value parts of the pair are called elements. The number of association pairs is said to be the size of the map.
An example of how the Map data type can be used is shown in the following program.
Here we are defining a Map M1 which has 2 mappings. The map_size is an inbuilt function defined in Erlang which can be used to determine the size of the map.
Example
-module(helloworld). -export([start/0]). start() -> M1 = #{name=>john,age=>25}, io:fwrite("~w",[map_size(M1)]).
The output of the above program will be as follows.
Output
2
Some of the other methods available for maps are as follows.
Sr.No. | Methods & Description |
---|---|
1 |
This method is used to generate a map from a list. |
2 |
This method is used to find if a particular key exists in the map. |
3 |
This method is used to get the value of a particular key in the map. |
4 |
This method is used to determine if a particular key is defined as a key in the map. |
5 |
This method is used to return all the keys from a map. |
6 |
This method is used to merge 2 maps. |
7 |
This method is used to add a key value pair to the map. |
8 |
This method is used to return all the values from a map. |
9 |
This method is used to remove a key value from the map. |