iteraptor v1.12.1 Iteraptor.Extras View Source

Extra functions to deal with enumerables.

Link to this section Summary

Functions

Deep store the value into the nested structure. Behaves as a proposed but rejected in ruby core Hash#bury.

Behaves as Enum.each_cons(n) in ruby. Iterates the input producing the list of cons. Gracefully stolen from https://groups.google.com/forum/#!topic/elixir-lang-core/LAK23vaJgvE

Link to this section Functions

Link to this function

bury(term, key, value, opts \\ [into: :default])

View Source

Specs

bury(
  Access.t(),
  [...],
  any(),
  [{:into, :default | :map | :keyword}] | Keyword.t()
) :: Access.t()

Deep store the value into the nested structure. Behaves as a proposed but rejected in ruby core Hash#bury.

Examples:

iex> Iteraptor.Extras.bury(%{foo: :bar}, ~w|a b c d|a, 42)
%{a: %{b: %{c: %{d: 42}}}, foo: :bar}
iex> Iteraptor.Extras.bury([foo: :bar], ~w|a b c d|a, 42)
[a: [b: [c: [d: 42]]], foo: :bar]
iex> Iteraptor.Extras.bury(%{foo: :bar}, ~w|a b c d|a, 42, into: :keyword)
%{a: [b: [c: [d: 42]]], foo: :bar}
iex> Iteraptor.Extras.bury(42, ~w|a b c d|a, 42)
** (Iteraptor.Utils.Unsupported) Unsupported term 42 in call to Iteraptor.Extras.bury/4.
Link to this function

each_cons(list, n \\ 2, acc \\ [])

View Source

Specs

each_cons([...] | %{} | binary(), integer(), Keyword.t()) :: [...]

Behaves as Enum.each_cons(n) in ruby. Iterates the input producing the list of cons. Gracefully stolen from https://groups.google.com/forum/#!topic/elixir-lang-core/LAK23vaJgvE

Examples

iex> 'letters' |> Iteraptor.Extras.each_cons
['le', 'et', 'tt', 'te', 'er', 'rs']
iex> 'letters' |> Iteraptor.Extras.each_cons(4)
['lett', 'ette', 'tter', 'ters']
iex> 1..6 |> Iteraptor.Extras.each_cons(4)
[[1,2,3,4], [2,3,4,5], [3,4,5,6]]
iex> "letters" |> Iteraptor.Extras.each_cons(3)
["let", "ett", "tte", "ter", "ers"]