# `Hephaestus.Core.Context`
[🔗](https://github.com/hephaestus-org/hephaestus_core/blob/v0.3.1/lib/hephaestus/core/context.ex#L1)

Workflow execution context carrying initial data and step results.

The context has two namespaced sections:

  * `initial` - immutable data provided when starting the workflow instance
  * `steps` - results accumulated from completed steps, keyed by step ref

Step results are always namespaced to avoid conflicts in fan-in scenarios
where parallel steps complete simultaneously.

## Example

    context = Context.new(%{order_id: 123})
    context = Context.put_step_result(context, :validate, %{valid: true})

    context.initial.order_id     #=> 123
    context.steps.validate.valid #=> true

# `t`

```elixir
@type t() :: %Hephaestus.Core.Context{initial: map(), steps: map()}
```

# `new`

```elixir
@spec new(map()) :: t()
```

Creates a new workflow context with the given initial data.

The `initial_data` map is stored under the `:initial` key and remains
immutable throughout the workflow execution. The `:steps` map starts empty
and is populated as steps complete.

## Parameters

  * `initial_data` - a map of data available to all steps in the workflow

## Returns

A `t:t/0` struct.

## Example

    iex> Context.new(%{order_id: 123})
    %Context{initial: %{order_id: 123}, steps: %{}}

# `put_step_result`

```elixir
@spec put_step_result(t(), atom(), map()) :: t()
```

Stores a step's result in the context under the given reference.

The result is placed in the `:steps` map keyed by `step_ref`, making it
accessible to subsequent steps as `context.steps.<step_ref>`.

## Parameters

  * `context` - the current `t:t/0` struct
  * `step_ref` - an atom identifying the step (matches the ref in the workflow graph)
  * `result` - a map containing the step's output data

## Returns

An updated `t:t/0` struct with the new step result merged into `:steps`.

## Example

    iex> context = Context.new(%{order_id: 123})
    iex> Context.put_step_result(context, :validate, %{valid: true})
    %Context{initial: %{order_id: 123}, steps: %{validate: %{valid: true}}}

---

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