RDF list library for TerminusDB.
Provides 17 functions for manipulating RDF rdf:List structures using
WOQL primitives. Each function composes TerminusDB.WOQL.Query structs
using existing WOQL.* builders.
Variable name collisions are avoided via an internal localize/1 helper
that generates process-unique variable names using :erlang.unique_integer/1.
Quick start
import TerminusDB.WOQL
# Get the first element of an rdf:List
query = and_([
triple("v:List", "rdf:type", iri("rdf:List")),
TerminusDB.WOQL.RDFList.rdflist_peek("v:List", "v:First")
])
# Get all elements as an array
query = TerminusDB.WOQL.RDFList.rdflist_list("v:List", "v:Array")
Summary
Functions
Appends a value to the end of the list (allocates a new cell at rdf:nil).
Deletes all cons cells and returns rdf:nil as the new list value.
Drops/removes a single element at the given position.
Creates an empty rdf:List (binds to rdf:nil).
Inserts a value at a 0-indexed position (allocates a new cell).
Checks if the list is empty (equals rdf:nil).
Gets the last element of an rdf:List (the value of the cell whose rdf:rest is rdf:nil).
Gets the length of an rdf:List.
Collects all rdf:List elements into a single array variable.
Traverses the list, yielding each element as a separate binding.
Gets the element at a 0-indexed position.
Gets the element at a 1-indexed position.
Gets the first element (rdf:first) of an rdf:List.
Pops the first element in-place (deletes the head cell).
Pushes a value to the front of the list, returning the new head cell.
Extracts a slice [start, end) as an array.
Swaps elements at two positions.
Types
Functions
@spec rdflist_append(woql_var(), woql_var(), woql_var() | nil) :: woql_query()
Appends a value to the end of the list (allocates a new cell at rdf:nil).
Examples
iex> q = TerminusDB.WOQL.RDFList.rdflist_append("v:List", "v:Value")
iex> q.op
:and
@spec rdflist_clear(woql_var(), woql_var()) :: woql_query()
Deletes all cons cells and returns rdf:nil as the new list value.
Examples
iex> q = TerminusDB.WOQL.RDFList.rdflist_clear("v:List", "v:NewList")
iex> q.op
:and
@spec rdflist_drop(woql_var(), non_neg_integer() | woql_var()) :: woql_query()
Drops/removes a single element at the given position.
Examples
iex> q = TerminusDB.WOQL.RDFList.rdflist_drop("v:List", 1)
iex> q.op
:and
@spec rdflist_empty(woql_var()) :: woql_query()
Creates an empty rdf:List (binds to rdf:nil).
Examples
iex> q = TerminusDB.WOQL.RDFList.rdflist_empty("v:List")
iex> q.op
:eq
@spec rdflist_insert( woql_var(), non_neg_integer() | woql_var(), woql_var(), woql_var() | nil ) :: woql_query()
Inserts a value at a 0-indexed position (allocates a new cell).
Examples
iex> q = TerminusDB.WOQL.RDFList.rdflist_insert("v:List", 1, "v:Value")
iex> q.op
:and
@spec rdflist_is_empty(woql_var()) :: woql_query()
Checks if the list is empty (equals rdf:nil).
Examples
iex> q = TerminusDB.WOQL.RDFList.rdflist_is_empty("v:List")
iex> q.op
:eq
@spec rdflist_last(woql_var(), woql_var()) :: woql_query()
Gets the last element of an rdf:List (the value of the cell whose rdf:rest is rdf:nil).
Examples
iex> q = TerminusDB.WOQL.RDFList.rdflist_last("v:List", "v:Last")
iex> q.op
:and
@spec rdflist_length(woql_var(), woql_var()) :: woql_query()
Gets the length of an rdf:List.
Examples
iex> q = TerminusDB.WOQL.RDFList.rdflist_length("v:List", "v:Len")
iex> q.op
:and
@spec rdflist_list(woql_var(), woql_var()) :: woql_query()
Collects all rdf:List elements into a single array variable.
Examples
iex> q = TerminusDB.WOQL.RDFList.rdflist_list("v:List", "v:Array")
iex> q.op
:and
@spec rdflist_member(woql_var(), woql_var()) :: woql_query()
Traverses the list, yielding each element as a separate binding.
Examples
iex> q = TerminusDB.WOQL.RDFList.rdflist_member("v:List", "v:Elem")
iex> q.op
:and
@spec rdflist_nth0(woql_var(), non_neg_integer() | woql_var(), woql_var()) :: woql_query()
Gets the element at a 0-indexed position.
Examples
iex> q = TerminusDB.WOQL.RDFList.rdflist_nth0("v:List", 2, "v:Elem")
iex> q.op
:and
@spec rdflist_nth1(woql_var(), pos_integer() | woql_var(), woql_var()) :: woql_query()
Gets the element at a 1-indexed position.
Examples
iex> q = TerminusDB.WOQL.RDFList.rdflist_nth1("v:List", 3, "v:Elem")
iex> q.op
:and
@spec rdflist_peek(woql_var(), woql_var()) :: woql_query()
Gets the first element (rdf:first) of an rdf:List.
Examples
iex> q = TerminusDB.WOQL.RDFList.rdflist_peek("v:List", "v:First")
iex> q.op
:triple
@spec rdflist_pop(woql_var(), woql_var()) :: woql_query()
Pops the first element in-place (deletes the head cell).
Examples
iex> q = TerminusDB.WOQL.RDFList.rdflist_pop("v:List", "v:Value")
iex> q.op
:and
@spec rdflist_push(woql_var(), woql_var(), woql_var()) :: woql_query()
Pushes a value to the front of the list, returning the new head cell.
The caller must update their reference to the new head cell. The original
list is not modified — the new cell's rdf:rest points to the original
list head.
Examples
iex> q = TerminusDB.WOQL.RDFList.rdflist_push("v:List", "v:Value", "v:NewHead")
iex> q.op
:and
@spec rdflist_slice( woql_var(), non_neg_integer() | woql_var(), non_neg_integer() | woql_var(), woql_var() ) :: woql_query()
Extracts a slice [start, end) as an array.
Examples
iex> q = TerminusDB.WOQL.RDFList.rdflist_slice("v:List", 0, 3, "v:Result")
iex> q.op
:and
@spec rdflist_swap( woql_var(), non_neg_integer() | woql_var(), non_neg_integer() | woql_var() ) :: woql_query()
Swaps elements at two positions.
Examples
iex> q = TerminusDB.WOQL.RDFList.rdflist_swap("v:List", 0, 2)
iex> q.op
:and