iteraptor v0.5.0 Iteraptor.Iteraptable
use Iteraptor.Iteraptable inside structs to make them both
Enumerable and
Collectable:
defmodule Iteraptor.Struct do
@fields [field: nil]
def fields, do: @fields
defstruct @fields
use Iteraptor.Iteraptable
end
iex> %Iteraptor.Struct{field: 42}
...> |> Enum.each(fn e -> Logger.debug(inspect(e)) end)
:ok
#⇒ {:field, 42}
Usage
Use the module within the struct of your choice and this struct will be
automagically granted Enumerable and Collectable protocols implementations.
Summary
Macros
Allows to enable iterating features on structs with use Iteraptor.Iteraptable
Macros
Allows to enable iterating features on structs with use Iteraptor.Iteraptable
Parameters
opts:Keywordthat currently might consist ofskip: collectableto makeIteraptorto implementEnumerableprotocol only
Examples
iex> %Iteraptor.Struct{field: 42}
...> |> Enum.map(fn {k, v} -> {k, v * 2} end)
...> |> Enum.into(%Iteraptor.Struct{})
%Iteraptor.Struct{field: 84}