dhaspden / transmog Goto Github PK
View Code? Open in Web Editor NEWEasily perform a deep in-place key remapping on lists and maps in Elixir.
License: MIT License
Easily perform a deep in-place key remapping on lists and maps in Elixir.
License: MIT License
Integers as map keys are valid in Elixir. We'll need to find a way to support them somehow. I'll need to ponder what the syntax for the key mapping string would look like... If anyone has any suggestions I'd be open to hearing them!
Example:
iex> key_map = [{"1", "one"}]
iex> data = %{1 => "abc"}
iex> {:ok, formatted_data} = Transmog.format(data, key_map)
iex> formatted_data
%{"one" => "abc"}
Currently maps with keys which have the period character in them are not mapped as you'd expect. We should support the period character by allowing it to be escaped. Escaped periods will not trigger the split in Transmog.Parser
.
Examples:
iex> Transmog.Parser.parse([{"a\.b", "b\.a"}])
[{["a.b", "b.a"}]
I think it would be awesome to support a third element in the tuple which is a transformer function. This function will transform the value (if it's set of course) to whatever the return value of the callback function is.
Example:
iex> key_mapping = [{"a", ":a", &Integer.parse/1}]
iex> data = %{"a" => "123"}
iex> {:ok, formatted_data} = Transmog.format(data, key_mapping)
iex> formatted_data
%{a: 123}
Sometimes we know that the data we are providing is correct and don't want to have to pattern match out the result from {:ok, data}
. We should give the developer the option to opt for use a bang version of the function if they want to.
Example:
iex> key_map = [{"a", ":a"}]
iex> data = %{"a" => "b"}
iex> Transmog.format!(data, key_map)
%{a: "b"}
Eventually when I am happy with this library I will need to post to Hex. I will close this issue when that is done. ๐
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.