Rujira.Enum (rujira_ex v0.0.1)

Copy Markdown View Source

Custom enum utilities for safer and more efficient list processing.

Summary

Functions

Runs the given function concurrently over the enum using Task.async_stream/3, short-circuiting on the first error, and collecting only successful results.

Iterates over an enumerable, applying a function that returns {:ok, value}, {:error, reason}, or :skip.

Returns a list of unique elements from the given enumerable, preserving order.

Functions

reduce_async_while_ok(enum, fun, opts \\ [])

@spec reduce_async_while_ok(Enumerable.t(), (term() -> term()), keyword()) ::
  {:ok, list()} | {:error, term()}

Runs the given function concurrently over the enum using Task.async_stream/3, short-circuiting on the first error, and collecting only successful results.

reduce_while_ok(enum, initial_acc \\ [], fun)

@spec reduce_while_ok(Enumerable.t(), list(), (term() ->
                                           {:ok, term()}
                                           | {:error, term()}
                                           | :skip)) ::
  {:ok, list()} | {:error, term()}

Iterates over an enumerable, applying a function that returns {:ok, value}, {:error, reason}, or :skip.

  • Accumulates all returned values into a list.
  • Halts and returns {:error, reason} if any element returns an error.
  • Skips over elements if :skip is returned.
  • Returns {:ok, list} when all elements succeed.

uniq(enum)

@spec uniq(Enumerable.t()) :: list()

Returns a list of unique elements from the given enumerable, preserving order.