/ex-make_enumerable

Makes your defstructs enumerable

Primary LanguageElixirMIT LicenseMIT

MakeEnumerable

Travis Hex.pm Version license

Makes your structures enumerable!

The MakeEnumerable module injects defimpl Enumerable for your structs, as structs are basically maps with special tag (member) __struct__. The module hides the tag __struct__ and delegates all other members to map to be Enumerable.

defmodule Bar do
  use MakeEnumerable
  defstruct foo: "a", baz: 10
end

iex> import Bar
iex> Enum.map(%Bar{}, fn({k, v}) -> {k, v} end)
[baz: 10, foo: "a"]

Installation

If available in Hex, the package can be installed by adding make_enumerable to your list of dependencies in mix.exs:

def deps do
  [
    {:make_enumerable, "~> 0.0.1"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/make_enumerable.