ryo33
Transmap - A library to transform a map with a rule of the same shape
Links
Examples
# Basic transformation:
map = %{a: 1, b: 2, c: 3}
rule = %{a: true}
Transmap.transform(map, rule)
== %{a: 1}
map = %{a: %{b: 1, c: 2}, d: %{e: 3, f: 4}, g: %{h: 5}}
rule = %{a: %{c: true}, d: true, g: %{i: true}}
Transmap.transform(map, rule)
== %{a: %{c: 2}, d: %{e: 3, f: 4}, g: %{}}
Transmap.transform(map, rule, diff: true)
== %{a: %{c: 2}, d: %{e: 3, f: 4}}
# Transfomation with _default:
map = %{a: 1, b: 2, c: %{d: 3, e: 4}}
rule = %{_default: true, b: false, c: %{_default: true}}
Transmap.transform(map, rule)
== %{a: 1, c: %{d: 3, e: 4}}
# Transformation with _spread:
map = %{a: %{b: 1, c: 2}, d: %{e: %{f: 3, g: 4}, h: 5}}
rule = %{_spread: [[:a], [:d, :e]], a: true, d: %{e: %{f: true}}}
Transmap.transform(map, rule)
== %{b: 1, c: 2, d: %{}, f: 3}
Transmap.transform(map, rule, diff: true)
== %{b: 1, c: 2, f: 3}
# Transformation with renaming:
map = %{a: 1, b: 2, c: %{d: 3, e: 4}, f: %{g: 5}}
rule = %{_spread: [[:f]], a: {"A", true}, b: "B", c: {:C, %{d: 6}}, f: %{g: "G"}}
Transmap.transform(map, rule)
== %{"A" => 1, "B" => 2, :C => %{6 => 3}, "G" => 5}
Popular in Libraries
Only 650 LOC, wrote for fun :slight_smile:
New
simple_feature_flags is a tiny package that lets you turn features on or off based on which environment (e.g. localhost, staging, product...
New
TypeCheck: Fast and flexible runtime type-checking for your Elixir projects.
Core ideas
Type- and function specifications are const...
New
I’m excited to announce that TaxJar has developed and open-sourced DateTimeParser. We developed it because we found a need to parse user ...
New
I’ve been working on two packages (not on hex.pm yet) to build admin interfaces for phoenix apps:
bureaucrat - which contains a bunch ...
New
Hello there,
I would like to share a feature toggles library (AKA feature flags) I’ve been working on.
The main package is FunWithFlags...
New
The latest release of Ace (0.10.0) includes serving content over HTTP/2.
I have started writing a webserver to teach my self more about...
New
I released Doggo, a collection of unstyled Phoenix components.
Features
Unstyled Phoenix components.
Storybook that can be added to...
New
Hello everyone,
I wrote a small library today called MapDiff.
It returns a map listing the (smallest amount of) changes to get from map...
New
Bandit is an HTTP server for Plug and WebSock apps.
Bandit is written entirely in Elixir and is built atop Thousand Island. It can serve...
New
Other popular topics
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
In Ruby, I can go:
User.find_by(email: "foobar@email.com").update(email: "hello@email.com")
How can I do something similar in Elixir? ...
New
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
Hi,
I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
I tried installing
elixir 1.11.2
erlang 23.3.4
via asdf in my zsh shell. Enabled the versions locally and globally.
When I list them ...
New
Hi all,
I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I'm trying to use Postg...
New
Hello guys,
I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New







