GithubHelp home page GithubHelp logo

dhaspden / transmog Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 1.0 91 KB

Easily perform a deep in-place key remapping on lists and maps in Elixir.

License: MIT License

Elixir 100.00%
elixir key-mapper

transmog's People

Contributors

dhaspden avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

zpeters

transmog's Issues

Somehow support integer keys

Features:

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"}

Support the literal "." with escaping

Features:

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"}]

Key mapping should also support the ability to map the value on that field

Features:

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}

Need to add a `format!/2` function which raises an exception if it fails

Features:

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"}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.