View Source ExAequoBase.Io (ExAequoBase v0.1.1)

Transform input from files, stdin, or binaries

Summary

Functions

From an enumerable of lines, create a list of tuples containing lines and line_numbers

Same as numbered_lines but just returning a stream

Types

@type atoms() :: [atom()]
@type binaries() :: [binary()]
@type either(lt, rt) :: ok_t(lt) | error_t(rt)
@type error_t() :: {:error, binary()}
@type error_t(t) :: {:error, t}
@type input_source_t() :: Enumerable.t() | binary() | binaries()
@type maybe(t) :: nil | t
@type natural() :: non_neg_integer()
@type numbered(t) :: {t, number()}
@type numbered_line_t() :: numbered(binary())
@type numbered_lines_t() :: [numbered_line_t()]
@type ok_t() :: {:ok, any()}
@type ok_t(t) :: {:ok, t}
@type reducer_result_t() :: {:halt, error_t()} | {:cont, ok_t()}
@type result_fun_t() :: (any() -> result_t())
@type result_fun_t(t) :: (any() -> result_t(t))
@type result_t() :: either(any(), binary())
@type result_t(t) :: either(t, binary())
@type stream_t() ::
  %IO.Stream{device: term(), line_or_bytes: term(), raw: term()}
  | %File.Stream{
      line_or_bytes: term(),
      modes: term(),
      node: term(),
      path: term(),
      raw: term()
    }

Functions

Link to this function

numbered_lines(input, initial_lnb \\ 1)

View Source
@spec numbered_lines(input_source_t(), number()) :: numbered_lines_t()

From an enumerable of lines, create a list of tuples containing lines and line_numbers

iex(1)> numbered_lines(~W[a b c])
[{"a", 1}, {"b", 2}, {"c", 3}]  

You can start with any number you want

iex(2)> numbered_lines(~W[a b c], -1.5)
[{"a", -1.5}, {"b", -0.5}, {"c", 0.5}]  

Why is this in a module called Io?

iex(3)> numbered_lines(fixture_stream!("three_lines"), 2)
[{"alpha", 2}, {"beta", 3}, {"gamma", 4}]  
Link to this function

numbered_lines_stream(input_source, initial_lnb \\ 1)

View Source
@spec numbered_lines_stream(input_source_t(), number()) :: Enumerable.t()

Same as numbered_lines but just returning a stream

iex(4)> s = numbered_lines_stream(~W[x y])
...(4)> assert is_function(s)
...(4)> s |> Enum.into([])
[{"x", 1}, {"y", 2}]