# `Imp.Example`
[🔗](https://github.com/deepfates/imp/blob/v0.18.1/lib/imp/example.ex#L1)

Flexible row of named data used for train/dev/test sets.

Examples are plain data with one important Imp convention: call
`with_inputs/2` to mark which fields a program may see. The remaining fields
are labels for evaluation, bootstrapping, demonstrations, and optimizers.
Until inputs are declared, `inputs/1` and `labels/1` raise, since no field
can be told apart from a label.

A key keeps the type it was given: `%{"question" => ...}` is stored under the
string and `%{question: ...}` under the atom, and no string is turned into an
atom. Every function that takes a key compares keys by their text, so
`get(example, :question)` reads a field stored under `"question"`, and
`new/1` refuses a field given under both spellings.

Internal fields whose names start with `imp_` are omitted from `keys/1`,
`items/1`, and `values/1`, but `to_map/1` remains lossless for persistence and
debugging.

## Example

    iex> example =
    ...>   Imp.Example.new(question: "2+2?", answer: "4", imp_trace: :kept)
    ...>   |> Imp.Example.with_inputs(:question)
    iex> Imp.Example.to_map(Imp.Example.inputs(example))
    %{question: "2+2?"}
    iex> Imp.Example.to_map(Imp.Example.labels(example))
    %{answer: "4", imp_trace: :kept}
    iex> Imp.Example.keys(example) |> Enum.sort()
    [:answer, :question]

# `t`

```elixir
@type t() :: %Imp.Example{
  demos: list(),
  fields: map(),
  input_keys: [atom() | String.t()] | nil
}
```

# `delete`

Returns a copy of the example with one field removed.

# `fetch!`

Reads a field or raises `KeyError` when it is missing.

# `get`

Reads a field, returning `default` when it is missing.

# `inputs`

Returns an example containing only the marked input fields.

Raises `ArgumentError` when `with_inputs/2` was never called: without a
declared split every field, labels included, would reach the program.

# `items`

Returns non-internal `{key, value}` field pairs.

# `keys`

Returns non-internal field keys.

# `labels`

Returns an example containing label fields, excluding marked inputs.

Raises `ArgumentError` when `with_inputs/2` was never called, as `inputs/1`
does.

# `new`

Builds an example from a map, field pair list, or existing example.

# `put`

Returns a copy of the example with one field set.

# `to_map`

Returns the full field map, including internal `imp_` fields.

# `values`

Returns non-internal field values.

# `with_demos`

Attaches demonstrations to an example.

# `with_inputs`

Marks which fields are inputs for programs and optimizers.

---

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