When To Use Elixir Range, Keyword Lists And MapSet — Tentamen Software Testing Blog

Elixir Range data type


In the previous post, we introduced the last two Elixir Basic Types, Reference, And Pid. Today we present higher-level types: Range, Keyword Lists, and MapSet. This post is part of the functional language series, and it is based on the remarkable book Elixir In Action by Sasa Juric.

Basic Vs. Higher Level Data Types

Elixir Basic data types are inherited from Erlang. The reason is simple, we need those to run Elixir programs on BEAM virtual machine. But to reduce the amount of boilerplate code, we need some higher-level data abstractions.


The Range represents a consecutive set of integer numbers. It is enumerable (implements enumerable behavior), and we could use all Enum module functions with Range. The operator in helps us to determine if the number is part of a range.

Keyword Lists

Elixir Keyword List

Keyword list is a list of tuples, where the first tuple element is an atom. In Elixir it is used as an optional list of function parameters. Many Elixir libraries stick to that convention. We have two options to define a Keyword list and two options to use it as a function parameter. Remember that searching a list is O(n). Keyword lists are used over Maps as function parameters because they preserve element order, and one key could have multiply values.


Elixir MapSet

MapSet is an enumerable set of unique values of any type.


  • The Range is a consecutive set of Integer numbers
  • The Range is a map with a small memory footprint
  • Range is enumerable
  • Keyword Lists is a list of special tuples
  • There is a Keyword module
  • Keywords are useful as optional function parameters
  • MapSet is a set of unique values.

Originally published at https://blog.tentamen.eu on October 2, 2020.

Founder of Tentamen, software testing agency.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store