diff --git a/CHANGELOG.md b/CHANGELOG.md index 0028c37..eb3e12b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and - Turtle decoder - `RDF.Data.descriptions/1` returns all descriptions within a RDF data structure - `RDF.Description.first/2` returns a single object a predicate of a `RDF.Description` +- `RDF.Description.objects/2` with custom filter function ### Changed diff --git a/lib/rdf/description.ex b/lib/rdf/description.ex index c654099..be8e612 100644 --- a/lib/rdf/description.ex +++ b/lib/rdf/description.ex @@ -475,11 +475,17 @@ defmodule RDF.Description do ...> ]) |> RDF.Description.objects MapSet.new([RDF.uri(EX.O1), RDF.uri(EX.O2), RDF.bnode(:bnode)]) """ - def objects(%RDF.Description{predications: predications}) do + def objects(%RDF.Description{} = description), + do: objects(description, &RDF.resource?/1) + + @doc """ + The set of all resources used in the objects within a `RDF.Description` satisfying the given filter criterion. + """ + def objects(%RDF.Description{predications: predications}, filter_fn) do Enum.reduce predications, MapSet.new, fn ({_, objects}, acc) -> objects |> Map.keys - |> Enum.filter(&RDF.resource?/1) + |> Enum.filter(filter_fn) |> MapSet.new |> MapSet.union(acc) end