Sitemap
Better Programming

Advice for programmers.

Member-only story

Elixir Associative Data Structures: Maps and Keyword Lists

3 min readAug 31, 2022

--

Taken from https://elixir-lang.org/

Associative data structures allow one to associate a key with a given value. In Python, they are called dictionaries; in JS, they are called literal objects. In Elixir, there are two: keyword lists and maps.

Keyword List

They are typically used to send options to functions. Let’s see an example where a keyword list is used.

Suppose we have a binary with three numbers separated by spaces, and we want to get a list containing these numbers. This can be done easily by placing the binary string and the separator in the split function inside the String module.

But what happens when we have more spaces in the binary string?

--

--

No responses yet