Provide fallback implementations for Enumerable.slice/1

This commit is contained in:
Marcel Otto 2018-03-09 23:18:08 +01:00
parent 4b26493c9f
commit 56436f85af
4 changed files with 11 additions and 6 deletions

View file

@ -726,8 +726,9 @@ defmodule RDF.Dataset do
defimpl Enumerable do defimpl Enumerable do
def member?(graph, statement), do: {:ok, RDF.Dataset.include?(graph, statement)} def member?(dataset, statement), do: {:ok, RDF.Dataset.include?(dataset, statement)}
def count(graph), do: {:ok, RDF.Dataset.statement_count(graph)} def count(dataset), do: {:ok, RDF.Dataset.statement_count(dataset)}
def slice(_dataset), do: {:error, __MODULE__}
def reduce(%RDF.Dataset{graphs: graphs}, {:cont, acc}, _fun) def reduce(%RDF.Dataset{graphs: graphs}, {:cont, acc}, _fun)
when map_size(graphs) == 0, do: {:done, acc} when map_size(graphs) == 0, do: {:done, acc}

View file

@ -572,6 +572,7 @@ defmodule RDF.Description do
defimpl Enumerable do defimpl Enumerable do
def member?(desc, triple), do: {:ok, RDF.Description.include?(desc, triple)} def member?(desc, triple), do: {:ok, RDF.Description.include?(desc, triple)}
def count(desc), do: {:ok, RDF.Description.count(desc)} def count(desc), do: {:ok, RDF.Description.count(desc)}
def slice(_desc), do: {:error, __MODULE__}
def reduce(%RDF.Description{predications: predications}, {:cont, acc}, _fun) def reduce(%RDF.Description{predications: predications}, {:cont, acc}, _fun)
when map_size(predications) == 0, do: {:done, acc} when map_size(predications) == 0, do: {:done, acc}

View file

@ -600,8 +600,9 @@ defmodule RDF.Graph do
defimpl Enumerable do defimpl Enumerable do
def member?(desc, triple), do: {:ok, RDF.Graph.include?(desc, triple)} def member?(graph, triple), do: {:ok, RDF.Graph.include?(graph, triple)}
def count(desc), do: {:ok, RDF.Graph.triple_count(desc)} def count(graph), do: {:ok, RDF.Graph.triple_count(graph)}
def slice(_graph), do: {:error, __MODULE__}
def reduce(%RDF.Graph{descriptions: descriptions}, {:cont, acc}, _fun) def reduce(%RDF.Graph{descriptions: descriptions}, {:cont, acc}, _fun)
when map_size(descriptions) == 0, do: {:done, acc} when map_size(descriptions) == 0, do: {:done, acc}
@ -615,6 +616,7 @@ defmodule RDF.Graph do
def reduce(%RDF.Graph{} = graph, {:suspend, acc}, fun) do def reduce(%RDF.Graph{} = graph, {:suspend, acc}, fun) do
{:suspended, acc, &reduce(graph, &1, fun)} {:suspended, acc, &reduce(graph, &1, fun)}
end end
end end

View file

@ -240,5 +240,6 @@ defmodule RDF.List do
def member?(_, _), do: {:error, __MODULE__} def member?(_, _), do: {:error, __MODULE__}
def count(_), do: {:error, __MODULE__} def count(_), do: {:error, __MODULE__}
def slice(_), do: {:error, __MODULE__}
end end
end end