Skip to main content
100%

filter maps in elixir

✓ Published0🌍 Public
Aallyraza
Last edited Oct 28, 2015
Created on Oct 28, 2015

This example demonstrates two different approaches to filtering maps in Elixir. It shows how to remove entries with falsy values from a map using `Enum.reduce` and `Map.put`, building a new map that only contains truthy key-value pairs. It then contrasts this with `Enum.filter`, which returns a list of tuples rather than a map, and accesses the result with bracket notation like `result[:val]`. The code defines an input map with mixed values (`:result`, `:description`, `:val`) and inspects both outputs, highlighting the behavioral difference between reducing into a map and filtering into a list.

AI-generated description

Similar vizzes