# 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 [](

### 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)
  # auto mapping can be turned off
  map A, B, :a_to_b, auto: false do

  map B, A, :b_to_a do
      # Keys that shouldn't be mapped can be dropped
### 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.

* `map(from_module, to_module, name_of_fn, opts) do ...`\
  Setup a new mapping function
* `let(from_symbol, to_symbol)`\
  Set field to field mapping
* `drop(from_symbol)`\
  Prevent a source field from being mapped
* `const(to_symbol, value)`\
  Provide a constant value for a destination field
* `nest(nested_module, dest_key) do ...`\
  Specify a nested struct type, and a destination field for it.

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