Improve RDF.Description.pop/1

This commit is contained in:
Marcel Otto 2020-07-26 23:01:43 +02:00
parent 909e2bde18
commit 3f6393a191

View file

@ -529,13 +529,12 @@ defmodule RDF.Description do
def pop(description)
def pop(description = %__MODULE__{predications: predications})
when predications == %{},
when map_size(predications) == 0,
do: {nil, description}
def pop(%__MODULE__{subject: subject, predications: predications}) do
# TODO: Find a faster way ...
predicate = List.first(Map.keys(predications))
[{object, _}] = Enum.take(objects = predications[predicate], 1)
[{predicate, objects}] = Enum.take(predications, 1)
[{object, _}] = Enum.take(objects, 1)
popped =
if Enum.count(objects) == 1,