# `OpenUI.Stream`
[🔗](https://github.com/ideia4it/openui/blob/v0.1.1/lib/openui/stream.ex#L1)

Parses a response a chunk at a time (language.md, section 4).

After every chunk, `program/1` gives a program that renders: completed
statements are read once and kept, and the cut-off tail is closed
implicitly and read again on each chunk. A cut-off statement never replaces
a completed one with the same name. When the host ends the stream with
`finish/1`, the program equals a batch parse of the whole text.

    stream =
      MyApp.Library
      |> OpenUI.Stream.new()
      |> OpenUI.Stream.push("root = Stack([title])\ntitle = Te")

    OpenUI.Stream.program(stream)

# `t`

```elixir
@type t() :: %OpenUI.Stream{
  buffer: String.t(),
  completed: [OpenUI.Statement.t()],
  completed_prefix: String.t(),
  final: OpenUI.Program.t() | nil,
  held: binary(),
  library: OpenUI.Library.t()
}
```

# `finish`

```elixir
@spec finish(t()) :: t()
```

Ends the stream: the cut-off tail completes, as in a batch parse of the whole text.

# `finished?`

```elixir
@spec finished?(t()) :: boolean()
```

True once `finish/1` ran.

# `new`

```elixir
@spec new(OpenUI.Library.t() | module()) :: t()
```

Starts a stream for a library.

# `program`

```elixir
@spec program(t()) :: OpenUI.Program.t()
```

The program as of the latest chunk.

# `push`

```elixir
@spec push(t(), String.t()) :: t()
```

Adds the next chunk. A chunk after `finish/1` starts a new stream.

# `text`

```elixir
@spec text(t()) :: binary()
```

The text received so far, including the bytes held back from a character
the last chunk cut, so a caller can take the next chunk as what comes after it.

---

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