Iteraptor.Extras (iteraptor v1.15.0)
View SourceExtra functions to deal with enumerables.
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
Functions
@spec 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.
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> ~c"letters" |> Iteraptor.Extras.each_cons
[~c"le", ~c"et", ~c"tt", ~c"te", ~c"er", ~c"rs"]
iex> ~c"letters" |> Iteraptor.Extras.each_cons(4)
[~c"lett", ~c"ette", ~c"tter", ~c"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"]