# `Estructura.Flattenable`
[🔗](https://github.com/am-kantox/estructura/blob/v1.12.0/lib/estructura/flattenable.ex#L1)

# `t`

```elixir
@type t() :: term()
```

All the types that implement this protocol.

# `flatten`

```elixir
@spec flatten(
  t(),
  keyword()
) :: term()
```

The function returning the flattened input.

This protocol is explicitly handful when deeply nested structs are to be serialized.

```elixir
iex|%_{}|1 ▶ %Estructura.User{}
%Estructura.User{
  address: %Estructura.User.Address{
    city: nil,
    street: %Estructura.User.Address.Street{house: nil, name: []}
  },
  data: %Estructura.User.Data{age: nil},
  name: nil
}

iex|%_{}|2 ▶ Estructura.Flattenable.flatten(%Estructura.User{}, coupler: "-", except: ~w|address-street data-age|)
%{"address-city" => nil, "birthday" => nil, "created_at" => nil, "name" => nil}
iex|%_{}|3 ▶ Estructura.Flattenable.flatten(%Estructura.User{}, only: ~w|address_street data_age|)
%{"address_street_house" => nil, "data_age" => nil}
iex|%_{}|4 ▶ Estructura.Flattenable.flatten(%Estructura.User{}, only: ~w|address|)
%{"address_city" => nil, "address_street_house" => nil}
```

Allowed options are:

- **`coupler`** the string to concatenate nested keys with, _default:_ **`-`** 
- **`only`** the list of keys to select
- **`except`** the list of keys to ignore
- **`jsonify`** `true` or a json encoder implementation; if set, the values will be jsonified

To enable it for your struct, use `@derive Estructura.Flattenable` or
  `@derive {Estructura.Flattenable, options}`. `Estructura` implementations derive it be default.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
