# `Macaw.Live.Edge.Mirror`
[🔗](https://github.com/dcoai/macaw_live/blob/v0.1.0/lib/macaw/live/edge.ex#L137)

A mirror of an edge (spec/04 §1): the last values a reading process holds of a node
another process owns, and the sequence they are as of. `Macaw.Live.Edge` is the owner's
side.

  * `new/2` takes a join's answer whole;
  * `take/3` reads a publication: the next sequence is applied, its values merged over
    the held ones; one at or below the held sequence is a repeat and ignored; one past
    the next is a gap, which the reader answers by joining again and taking the answer
    whole with `whole/2`, so no change is applied twice or lost;
  * `land/3` puts state values into the reader's `Macaw.State` with
    `Macaw.State.put/2`, judged by the reader's own declaration: a value it refuses is
    dropped, its faults kept in `dropped` for the reader's `info/1`.

# `t`

```elixir
@type t() :: %Macaw.Live.Edge.Mirror{
  dropped: [Macaw.Base.Fault.t()],
  key: term(),
  seq: integer() | nil,
  values: map()
}
```

A mirror: the edge's key, the sequence held, the values and the faults dropped.

# `land`

```elixir
@spec land(t(), Macaw.State.t(), map()) :: {t(), Macaw.State.t(), list()}
```

State values carried by the mirror put into the reader's state (spec/04 §1): `{mirror,
state, changed}`, `changed` the names whose values changed in name order. Each is judged
by the reader's declaration as `Macaw.State.restore/3` judges a stored value
(`Macaw.State.put/2`); a value it refuses is left out, the state's own value kept, and
its faults appended to the mirror's `dropped`. A visitor's overlay the visit carries
is taken as the visit holds it, its name `{:overlay, source}` first among `changed`
(`Macaw.Live.Scopes.land/2`).

# `new`

```elixir
@spec new(term(), {:ok, integer(), map()}) :: t()
```

A mirror of `key` holding a join's answer.

    iex> mirror = Macaw.Live.Edge.Mirror.new("wall", {:ok, 7, %{"pick" => nil}})
    iex> {mirror.seq, mirror.values}
    {7, %{"pick" => nil}}

# `take`

```elixir
@spec take(t(), integer(), map()) :: {:applied, t(), map()} | :repeat | :gap
```

A publication read (spec/04 §1): `{:applied, mirror, changed}` for the next sequence,
`changed` its values; `:repeat` for one at or below the held sequence; `:gap` for one
past the next, which the reader answers by joining again (`whole/2`).

    iex> alias Macaw.Live.Edge.Mirror
    iex> mirror = Mirror.new("wall", {:ok, 7, %{"pick" => nil}})
    iex> {:applied, mirror, %{"pick" => "a"}} = Mirror.take(mirror, 8, %{"pick" => "a"})
    iex> {Mirror.take(mirror, 8, %{"pick" => "b"}), Mirror.take(mirror, 10, %{"pick" => "c"})}
    {:repeat, :gap}

# `whole`

```elixir
@spec whole(t(), {:ok, integer(), map()}) :: {t(), map()}
```

A join's answer taken whole, after a gap or the owner's `:DOWN`: `{mirror, changed}`,
`changed` the values that differ from the ones held.

---

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