View Source Estructura.Transformer protocol (estructura v0.6.0)

Link to this section Summary

Functions

The function returning the transformed input to be used with Inspect protocol.

Link to this section Types

Link to this section Functions

Link to this function

transform(input, options \\ [])

View Source
@spec transform(
  t(),
  keyword()
) :: term()

The function returning the transformed input to be used with Inspect protocol.

This protocol is explicitly handful when deeply nested structs are to be logged/inspected.

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.Transformer.transform %Estructura.User{}, type: false, except: ~w|address.street data.age|
[address: [city: nil], data: [], name: nil]
iex|%_{}|3  Estructura.Transformer.transform %Estructura.User{}, type: false, only: ~w|address.street data.age|
[address: [street: [house: nil, name: []]], data: [age: nil]]
iex|%_{}|4  Estructura.Transformer.transform %Estructura.User{}, only: ~w|address|
[
  *: Estructura.User,
  address: [
    *: Estructura.User.Address,
    city: nil,
    street: [*: Estructura.User.Address.Street, house: nil, name: []]
  ]
]

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