Extra v0.2.0 Stream.Extra

Extensions to the built-in Stream module.

Link to this section Summary

Functions

Filters out the nil and {_, nil} values from an Enumerable

Executes fun after enum has finished

Streams tuples in the form of {:ok, any} or {:error, any}. Rejects :error tuples while unwrapping :ok tuples

Unwraps a stream of {:ok, any} tuples. Raises an ArgumentError if it encounters a {:error, ...} tuple

Link to this section Functions

Link to this function filter_nil_values(stream)
filter_nil_values(Enumerable.t) :: Enumerable.t

Filters out the nil and {_, nil} values from an Enumerable.

iex> Stream.Extra.filter_nil_values([1, 2, nil]) |> Enum.to_list [1, 2]

iex> Stream.Extra.filter_nil_values(%{a: “test”, b: nil}) |> Enum.into(%{}) %{a: “test”}

Link to this function on_finish(enum, fun)
on_finish(Enumerable.t, (() -> any)) :: Enumerable.t

Executes fun after enum has finished.

Link to this function unwrap_oks(stream)
unwrap_oks(Enumerable.t) :: Enumerable.t

Streams tuples in the form of {:ok, any} or {:error, any}. Rejects :error tuples while unwrapping :ok tuples.

iex> Stream.Extra.unwrap_oks([{:ok, 1}, {:error, “Test”}]) |> Enum.into([]) [1]

Link to this function unwrap_oks!(stream)
unwrap_oks!(Enumerable.t) :: Enumerable.t

Unwraps a stream of {:ok, any} tuples. Raises an ArgumentError if it encounters a {:error, ...} tuple.