Cartograf

Build Status

Struct-to-Struct Mapping Utility for Elixir

This Project is still under development, and may not be safe for production.

Documentation can be found at https://hexdocs.pm/cartograf.

Building Mapping Functions

defmodule A, do: defstruct [:a, :b, :cc, :d]
defmodule B, do: defstruct [:a, :b, :c, :d, :e]

defmodule YourModule do
use Cartograf

  map A, B, :a_to_b do
    [
      # No need to directly map identical keys, i.e. 
      # let(:a, :a)
      let(:cc, :c)
    ]
  end
  # auto mapping can be turned off
  map A, B, :a_to_b, auto: false do
    ...
  end

  map B, A, :b_to_a do
    [
      # Keys that shouldn't be mapped can be dropped
      drop(:e)
    ]
  end
end

Invoking Mapping Functions

iex> YourModule.a_to_b(%A{a: 1, b: 2, c: 3, d: 4})
%B{a: 1, b: 2, c: 3, d: 4, e: nil}

List of Forms

For more information, please look at the docs and tests.

Installation

The package can be installed by adding cartograf to your list of dependencies in mix.exs:

def deps do
  [
    {:cartograf, "~> 0.1.0"}
    # or
    {:cartograf, git: "https://github.com/Herlitzd/cartograf.git"}
  ]
end