Packages
iteraptor
1.7.2
1.15.0
1.14.0
1.13.1
1.13.0
1.12.2
1.12.1
1.12.0
1.11.0
1.10.3
1.10.2
1.10.1
1.9.0
1.8.0
1.7.3
1.7.2
1.7.1
1.7.0
1.6.1
1.6.0
1.4.1
1.4.0
1.3.2
1.2.1
1.2.0
1.1.1
1.1.0
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0
1.0.0-rc1
0.7.0
0.6.2
0.6.1
0.5.2
0.5.1
0.5.0
0.4.0
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.3.0
0.2.4
0.2.3
0.2.2
0.2.1
0.1.1
0.1.0
This small library allows the deep iteration / mapping of Enumerables.
Current section
Files
Jump to
Current section
Files
lib/iteraptable.ex
defprotocol Iteraptable do
@moduledoc """
The protocol specifying how the respective struct might be used within `Iteraptor`.
**Experimental.** By implementing this protocol one might change the behaviour of
nested objects regarding how they should be iterated through.
"""
@spec type(term :: any()) :: atom()
@doc "Returns a type understood by `Iteraptable`"
def type(term)
@spec to_enumerable(term :: any()) :: Enumerable.t()
@doc "Converts a term to an enumerable"
def to_enumerable(term)
@spec to_collectable(term :: any()) :: Collectable.t()
@doc "Converts a term to a collectable"
def to_collectable(term)
@spec name(term :: any()) :: binary()
@doc "Returns a name of the term to be represented in flatmaps"
def name(term)
end
defimpl Iteraptable, for: Date do
def name(_term), do: "s·date"
def type(_term), do: Date
if Version.compare(System.version(), "1.8.0") == :lt do
def to_enumerable(term), do: %{struct_date: Date.to_iso8601(term)}
else
def to_enumerable(term), do: %{struct_date: Date.to_iso8601(term)}
# def to_enumerable(term), do: %{s·date: Date.to_iso8601(term)}
end
def to_collectable(_term), do: %{}
end
defimpl Iteraptable, for: Time do
def name(_term), do: "s·time"
def type(_term), do: Time
if Version.compare(System.version(), "1.8.0") == :lt do
def to_enumerable(term), do: %{struct_time: Time.to_iso8601(term)}
else
def to_enumerable(term), do: %{struct_time: Time.to_iso8601(term)}
# def to_enumerable(term), do: %{s·time: Time.to_iso8601(term)}
end
def to_collectable(_term), do: %{}
end