Implement missing Enumerable for Buffer.
This commit is contained in:
parent
b84f95c3ce
commit
a1087d8320
2 changed files with 24 additions and 1 deletions
23
lib/enumerable/vivid/buffer.ex
Normal file
23
lib/enumerable/vivid/buffer.ex
Normal 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
|
2
mix.exs
2
mix.exs
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue