Iteraptor
Handy enumerable operations:
to_flatmap
Installation
-
Add
iteraptorto your list of dependencies inmix.exs:
```elixir
def deps do
[{:iteraptor, "~> 0.3.0"}]
end
```-
Ensure
iteraptoris started before your application:
```elixir
def application do
[applications: [:iteraptor]]
end
```Usage
iex> %{a: %{b: %{c: 42, d: [nil, 42]}, e: [:f, 42]}} |> Iteraptor.to_flatmap
%{"a.b.c" => 42, "a.b.d.0" => nil, "a.b.d.1" => 42, "a.e.0" => :f, "a.e.1" => 42}To be implicitly as explicit as possible, the current implementation creates string keys for those, containing joiner and atoms for those that haven’t.
That makes normal maps to be resistant to
iex> %{a: %{b: %{c: 42}}} |> Iteraptor.to_flatmap |> Iteraptor.from_flatmap
%{a: %{b: %{c: 42}}}
Changelog
As of version 0.3.0, the module supports
Keyword on input,
but it will be output as map for |> Iteraptor.to_flatmap |> Iteraptor.from_flatmap
back and forth transformation.
As of version 0.4.0, the module supports
structs on input.
Structs will be automagically created on |> Iteraptor.from_flatmap from
keys like StructName%field if a) this structure is known to the system
and b) keys are consistent (e. g. there are no subsequent elements,
belonging to different structs: ["S1%f" => 42, "S2%f" => 3.14].)
Please see examples for an inspiration.