# `RDF.Star.Triple`
[🔗](https://github.com/rdf-elixir/rdf-ex/blob/v3.0.1/lib/rdf/star/triple.ex#L1)

Helper functions for RDF-star triples.

An RDF-star triple is represented as a plain Elixir tuple consisting of three valid
RDF values for subject, predicate and object.
As opposed to an `RDF.Triple` the subject or object can be a triple itself.

# `coercible`

```elixir
@type coercible() ::
  {RDF.Star.Statement.coercible_subject(),
   RDF.Star.Statement.coercible_predicate(),
   RDF.Star.Statement.coercible_object()}
```

# `t`

```elixir
@type t() ::
  {RDF.Star.Statement.subject(), RDF.Star.Statement.predicate(),
   RDF.Star.Statement.object()}
```

# `new`

```elixir
@spec new(RDF.Star.Statement.coercible(), RDF.PropertyMap.t() | nil) :: t()
```

Creates a `RDF.Star.Triple` with proper RDF-star values.

An error is raised when the given elements are not coercible to RDF-star values.

Note: The `RDF.triple` function is a shortcut to this function.

## Examples

    iex> RDF.Star.Triple.new {"http://example.com/S", "http://example.com/p", 42}
    {~I<http://example.com/S>, ~I<http://example.com/p>, RDF.literal(42)}

    iex> RDF.Star.Triple.new {EX.S, EX.p, 42}
    {RDF.iri("http://example.com/S"), RDF.iri("http://example.com/p"), RDF.literal(42)}

    iex> RDF.Star.Triple.new {EX.S, EX.p, 42, EX.Graph}
    {RDF.iri("http://example.com/S"), RDF.iri("http://example.com/p"), RDF.literal(42)}

    iex> RDF.Star.Triple.new {EX.S, :p, 42}, RDF.PropertyMap.new(p: EX.p)
    {RDF.iri("http://example.com/S"), RDF.iri("http://example.com/p"), RDF.literal(42)}

    iex> RDF.Star.Triple.new({{EX.S, :p, 42}, :p2, 43}, RDF.PropertyMap.new(p: EX.p, p2: EX.p2))
    {{~I<http://example.com/S>, ~I<http://example.com/p>, RDF.literal(42)}, ~I<http://example.com/p2>, RDF.literal(43)}

# `new`

```elixir
@spec new(
  RDF.Star.Statement.coercible_subject(),
  RDF.Star.Statement.coercible_predicate(),
  RDF.Star.Statement.coercible_object(),
  RDF.PropertyMap.t() | nil
) :: t()
```

Creates a `RDF.Star.Triple` with proper RDF-star values.

An error is raised when the given elements are not coercible to RDF-star values.

Note: The `RDF.triple` function is a shortcut to this function.

## Examples

    iex> RDF.Star.Triple.new({"http://example.com/S", "http://example.com/p", 42}, "http://example.com/p2", 43)
    {{~I<http://example.com/S>, ~I<http://example.com/p>, RDF.literal(42)}, ~I<http://example.com/p2>, RDF.literal(43)}

    iex> RDF.Star.Triple.new({EX.S, EX.p, 42}, EX.p2, 43)
    {{~I<http://example.com/S>, ~I<http://example.com/p>, RDF.literal(42)}, ~I<http://example.com/p2>, RDF.literal(43)}

    iex> RDF.Star.Triple.new(EX.S, EX.p, 42)
    {RDF.iri("http://example.com/S"), RDF.iri("http://example.com/p"), RDF.literal(42)}

    iex> RDF.Star.Triple.new({EX.S, :p, 42}, :p2, 43, RDF.PropertyMap.new(p: EX.p, p2: EX.p2))
    {{~I<http://example.com/S>, ~I<http://example.com/p>, RDF.literal(42)}, ~I<http://example.com/p2>, RDF.literal(43)}

# `valid?`

```elixir
@spec valid?(t() | any()) :: boolean()
```

Checks if the given tuple is a valid RDF-star triple.

The elements of a valid RDF-star triple must be RDF terms. On the subject
position only IRIs, blank nodes and triples are allowed, while on the predicate
position only IRIs allowed. The object position can be any RDF term or triple.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
