structured_io v1.5.0 StructuredIO.Collector View Source

Provides a Collectable implementation for StructuredIO. Call StructuredIO.collect/1 instead of invoking this module directly.

Examples

iex> {:ok,
...>  structured_io} = StructuredIO.start_link(:unicode)
iex> {:ok,
...>  collector} = StructuredIO.Collector.new(%{process: structured_io,
...>                                            function: :write})
iex> ["<elem>foo</elem>",
...>  "<elem>bar</elem>",
...>  "<elem>baz</elem>"]
...> |> Enum.into(collector)
iex> StructuredIO.read_between structured_io,
...>                           "<elem>",
...>                           "</elem>"
"foo"
iex> StructuredIO.read_between structured_io,
...>                           "<elem>",
...>                           "</elem>"
"bar"
iex> StructuredIO.read_between structured_io,
...>                           "<elem>",
...>                           "</elem>"
"baz"
iex> StructuredIO.read_between structured_io,
...>                           "<elem>",
...>                           "</elem>"
""

Link to this section Summary

Functions

Builds a new StructuredIO.Collector for the specified StructuredIO process and function

Link to this section Types

Link to this type t() View Source
t() :: %StructuredIO.Collector{function: atom(), process: GenServer.server()}

A StructuredIO.Collector struct.

Link to this section Functions

Link to this function new(collector) View Source
new(%{process: GenServer.server(), function: atom()}) ::
  {:ok, t()} | StructuredIO.error()

Builds a new StructuredIO.Collector for the specified StructuredIO process and function.

Examples

iex> {:ok,
...>  collector} = StructuredIO.Collector.new(%{process: :a_process,
...>                                            function: :write})
iex> collector
%StructuredIO.Collector{process: :a_process,
                        function: :write}

iex> StructuredIO.Collector.new %{function: :write}
{:error,
 "StructuredIO.Collector :process field is required"}

iex> StructuredIO.Collector.new %{process: :a_process}
{:error,
 "StructuredIO.Collector :function field must be the name of a StructuredIO public function"}

iex> StructuredIO.Collector.new %{process: :a_process,
...>                              function: :not_a_function}
{:error,
 "function StructuredIO.not_a_function/2 is undefined or private"}