Implement missing Enumerable for Buffer.

This commit is contained in:
James Harton 2017-01-02 21:20:48 +13:00
parent b84f95c3ce
commit a1087d8320
2 changed files with 24 additions and 1 deletions

View file

@ -0,0 +1,23 @@
defimpl Enumerable, for: Vivid.Buffer do
alias Vivid.Buffer
@moduledoc """
Implements the Enumerable protocol for Buffer.
"""
@doc """
Returns the number of pixels in a buffer.
"""
def count(%Buffer{buffer: buffer}), do: {:ok, Enum.count(buffer) }
@doc """
Returns whether a colour is a member of a buffer.
This is mostly useless, but it's part of the Enumerable protocol.
"""
def member?(%Buffer{buffer: buffer}, colour), do: {:ok, Enum.member?(buffer, colour) }
@doc """
Reduce the buffer into an accumulator.
"""
def reduce(%Buffer{buffer: buffer}, acc, fun), do: Enumerable.List.reduce(buffer, acc, fun)
end

View file

@ -3,7 +3,7 @@ defmodule Vivid.Mixfile do
def project do
[app: :vivid,
version: "0.1.0",
version: "0.1.1",
description: description,
elixir: "~> 1.3",
build_embedded: Mix.env == :prod,