View Source DeepSinker (deep_sinker v2.0.0)
Customizable file traverser.
Link to this section Summary
Types
State of traversing.
Link to this section Types
@type item_type() :: :file | :directory | :ignore
@type marker() :: any()
@type new_option() :: {:order, order()}
@type next_option() :: {:handler, handler()}
@type next_result() :: {:ok, item()} | :done
@type order() :: :asc | :desc
@type path() :: String.t()
@type t() :: %DeepSinker{ found_but_not_used_yet_items: [item()], order: order(), root_items: [item()] }
State of traversing.
Link to this section Functions
@spec new([item()], [new_option()]) :: t()
Create initial state.
examples
Examples
iex> DeepSinker.new([{"/path/to/dir1", :dir1}, {"/path/to/dir2", :dir2}])
...> |> is_struct(DeepSinker)
true
iex> DeepSinker.new([{"/path/to/dir1", :dir1}, {"/path/to/dir2", :dir2}], order: :desc)
...> |> is_struct(DeepSinker)
true
@spec next(t(), [next_option()]) :: {t(), next_result()}
Pop file and update state.
examples
Examples
iex> DeepSinker.new([{"./", :marker}])
...> |> DeepSinker.next()
...> # {state, {:ok, {filepath, :marker}}} | {state, :done}
iex> DeepSinker.new([{"./", :marker}])
...> |> DeepSinker.next(
...> handler: fn {path, _marker} ->
...> cond do
...> String.ends_with?(path, ".git") -> :ignore
...> String.contains?(path, ".") -> :file
...> true -> :directory
...> end
...> end
...> )
...> # {state, {:ok, {filepath, :marker}}} | {state, :done}
@spec stream(t(), [next_option()]) :: Enumerable.t(item())
Stream filepaths.
examples
Examples
iex> DeepSinker.new([{"/path_a", :a}, {"/path_b", :b}])
...> # |> DeepSinker.stream()
...> # |> Enum.to_list()
...> # [{"/path_a/1.txt", :a}, {"/path_a/2.txt, :a} {"/path_b/1.txt, :b}]
iex> DeepSinker.new([{"/path_a", :a}, {"/path_b", :b}])
...> |> DeepSinker.stream(
...> handler: fn {path, _marker} ->
...> cond do
...> String.ends_with?(path, ".git") -> :ignore
...> String.contains?(path, ".") -> :file
...> true -> :directory
...> end
...> end
...> )
...> # [{"/path_a/1.txt", :a}, {"/path_a/2.txt, :a} {"/path_b/1.txt, :b}]