# `RDF.XSD.Boolean`
[🔗](https://github.com/rdf-elixir/rdf-ex/blob/v3.0.1/lib/rdf/xsd/datatypes/boolean.ex#L1)

`RDF.XSD.Datatype` for `xsd:boolean`.

See: <https://www.w3.org/TR/xmlschema11-2/#boolean>

# `input_value`

```elixir
@type input_value() :: RDF.Literal.t() | valid_value() | number() | String.t() | any()
```

# `invalid_value`

```elixir
@type invalid_value() :: nil
```

# `t`

```elixir
@type t() :: %RDF.XSD.Boolean{
  uncanonical_lexical: RDF.XSD.Datatype.uncanonical_lexical(),
  value: value()
}
```

# `valid_value`

```elixir
@type valid_value() :: boolean()
```

# `value`

```elixir
@type value() :: valid_value() | invalid_value()
```

# `canonical`

Produces the canonical representation of a `RDF.Literal` of this datatype.

# `canonical?`

Determines if the lexical form of a `RDF.Literal` of this datatype is the canonical form.

# `canonical_lexical`

Returns the canonical lexical form of a `RDF.Literal` of this datatype.

# `cast`

```elixir
@spec cast(RDF.Literal.Datatype.literal() | RDF.Term.t()) :: RDF.Literal.t() | nil
```

Casts a datatype literal of one type into a datatype literal of another type.

Returns `nil` when the given arguments are not castable into this datatype or when the given argument is an
invalid literal.

Implementations define the casting for a given value with the `c:RDF.Literal.Datatype.do_cast/1` callback.

# `compare`

```elixir
@spec compare(RDF.Literal.t() | any(), RDF.Literal.t() | any()) ::
  RDF.Literal.Datatype.comparison_result() | :indeterminate | nil
```

Compares two `RDF.Literal`s.

If the first literal is greater than the second `:gt` is returned, if less than `:lt` is returned.
If both literal are equal `:eq` is returned.
If the literals can not be compared either `nil` is returned, when they generally can be compared
due to their datatype, or `:indeterminate` is returned, when the order of the given values is
not defined on only partially ordered datatypes.

# `datatype?`

Checks if the given literal has this datatype or a datatype that is derived of it.

# `ebv`

```elixir
@spec ebv(input_value()) :: RDF.Literal.t() | nil
```

Returns an Effective Boolean Value (EBV).

The Effective Boolean Value is an algorithm to coerce values to a `RDF.XSD.Boolean`.

It is specified and used in the SPARQL query language and is based upon XPath's
`fn:boolean`. Other than specified in these specs any value which can not be
converted into a boolean results in `nil`.

see
- <https://www.w3.org/TR/xpath-31/#id-ebv>
- <https://www.w3.org/TR/sparql11-query/#ebv>

# `effective`

```elixir
@spec effective(input_value()) :: RDF.Literal.t() | nil
```

Alias for `ebv/1`.

# `equal_value?`

Checks if two datatype literals are equal in terms of the values of their value space.

Non-`RDF.Literal`s  are tried to be coerced via `RDF.Literal.coerce/1` before comparison.

Returns `nil` when the given arguments are not comparable as literals of this
datatype.

Invalid literals are only considered equal in this relation when both have the exact same
datatype and the same attributes (lexical form, language etc.).

Implementations can customize this equivalence relation via the `c:RDF.Literal.Datatype.do_equal_value_different_datatypes?/2`
and `c:RDF.Literal.Datatype.do_equal_value_different_datatypes?/2` callbacks.

# `fn_not`

```elixir
@spec fn_not(input_value()) :: t() | nil
```

Returns `RDF.XSD.true` if the effective boolean value of the given argument is `RDF.XSD.false`, or `RDF.XSD.false` if it is `RDF.XSD.true`.

Otherwise, it returns `nil`.

## Examples

    iex> RDF.XSD.Boolean.fn_not(RDF.XSD.true)
    RDF.XSD.false
    iex> RDF.XSD.Boolean.fn_not(RDF.XSD.false)
    RDF.XSD.true

    iex> RDF.XSD.Boolean.fn_not(true)
    RDF.XSD.false
    iex> RDF.XSD.Boolean.fn_not(false)
    RDF.XSD.true

    iex> RDF.XSD.Boolean.fn_not(42)
    RDF.XSD.false
    iex> RDF.XSD.Boolean.fn_not("")
    RDF.XSD.true

    iex> RDF.XSD.Boolean.fn_not(nil)
    nil

see <https://www.w3.org/TR/xpath-functions/#func-not>

# `lexical`

Returns the lexical form of a `RDF.Literal` of this datatype.

# `logical_and`

```elixir
@spec logical_and(input_value(), input_value()) :: t() | nil
```

Returns the logical `AND` of the effective boolean value of the given arguments.

It returns `nil` if only one argument is `nil` and the other argument is
`RDF.XSD.true` and `RDF.XSD.false` if the other argument is `RDF.XSD.false`.

## Examples

    iex> RDF.XSD.Boolean.logical_and(RDF.XSD.true, RDF.XSD.true)
    RDF.XSD.true
    iex> RDF.XSD.Boolean.logical_and(RDF.XSD.true, RDF.XSD.false)
    RDF.XSD.false

    iex> RDF.XSD.Boolean.logical_and(RDF.XSD.true, nil)
    nil
    iex> RDF.XSD.Boolean.logical_and(nil, RDF.XSD.false)
    RDF.XSD.false
    iex> RDF.XSD.Boolean.logical_and(nil, nil)
    nil

see <https://www.w3.org/TR/sparql11-query/#func-logical-and>

# `logical_or`

```elixir
@spec logical_or(input_value(), input_value()) :: t() | nil
```

Returns the logical `OR` of the effective boolean value of the given arguments.

It returns `nil` if only one argument is `nil` and the other argument is
`RDF.XSD.false` and `RDF.XSD.true` if the other argument is `RDF.XSD.true`.

## Examples

    iex> RDF.XSD.Boolean.logical_or(RDF.XSD.true, RDF.XSD.false)
    RDF.XSD.true
    iex> RDF.XSD.Boolean.logical_or(RDF.XSD.false, RDF.XSD.false)
    RDF.XSD.false

    iex> RDF.XSD.Boolean.logical_or(RDF.XSD.true, nil)
    RDF.XSD.true
    iex> RDF.XSD.Boolean.logical_or(nil, RDF.XSD.false)
    nil
    iex> RDF.XSD.Boolean.logical_or(nil, nil)
    nil

see <https://www.w3.org/TR/sparql11-query/#func-logical-or>

# `new`

Creates a new `RDF.Literal` with this datatype and the given `value`.

# `new!`

Creates a new `RDF.Literal` with this datatype and the given `value` or fails when it is not valid.

# `update`

Updates the value of a `RDF.Literal` without changing everything else.

# `valid?`

Determines if a `RDF.Literal` of this or a derived datatype has a proper value of its value space.

# `value`

Returns the value of a `RDF.Literal` of this or a derived datatype.

---

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