diff --git a/CHANGELOG.md b/CHANGELOG.md index 652284e..f15b9c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ This project adheres to [Semantic Versioning](http://semver.org/) and literals in Turtle encoder - `RDF.Numeric` with a list of all numeric datatypes and shared functions for all numeric literals, eg. arithmetic functions +- `RDF.Datatype.cast/1` for casting between `RDF.Literal`s as specified in the + XSD spec - the logical operators and the Effective Boolean Value (EBV) coercion algorithm from the XPath and SPARQL specs on `RDF.Boolean` - `RDF.DateTime.now/0` diff --git a/lib/rdf/datatype.ex b/lib/rdf/datatype.ex index 1075bde..6f3146f 100644 --- a/lib/rdf/datatype.ex +++ b/lib/rdf/datatype.ex @@ -35,7 +35,7 @@ defmodule RDF.Datatype do @doc """ Produces the canonical form of a `RDF.Literal`. """ - @callback canonical(literal :: RDF.Literal.t) :: RDF.Literal.t + @callback canonical(RDF.Literal.t) :: RDF.Literal.t @doc """ Converts a value into a proper native value. @@ -51,6 +51,16 @@ defmodule RDF.Datatype do """ @callback convert(any, keyword) :: any + + @doc """ + Casts a literal of another datatype into a literal of the datatype the function is implemented on. + + If the given literal is invalid or can not be converted into this datatype + `nil` is returned. + """ + @callback cast(RDF.Literal.t) :: RDF.Literal.t + + @doc """ Determines if the value of a `RDF.Literal` is a member of lexical value space of its datatype. """