Interval.Behaviour behaviour (Interval v2.0.1)
View SourceDefines the Interval behaviour. You'll usually want to use this behaviour by using
use Interval, type: MyType
In your own interval modules, instead of defining the behaviour directly.
Summary
Callbacks
Is this implementation of an interval considered discrete?
Create a new Interval.t/0
Create a new interval with the specified left and right endpoints, and bounds.
Compare two points, returning if a == b
, a > b
or a < b
.
Return a string representation of a point for use in formatting intervals.
Normalize a point to a canonical form. Returns :error if the point is invalid.
Parse a string representation of a point into a point, for use in parsing intervals.
Step a discrete point n
steps.
Types
@type new_opt() :: {:left, Interval.point()} | {:right, Interval.point()} | {:bounds, String.t()}
@type new_opts() :: [new_opt()]
Callbacks
@callback discrete?() :: boolean()
Is this implementation of an interval considered discrete?
The interval is implicitly continuous if not discrete.
@callback new(new_opts()) :: Interval.t()
Create a new Interval.t/0
@callback new(left :: Interval.point(), right :: Interval.point(), bounds :: String.t()) :: Interval.t()
Create a new interval with the specified left and right endpoints, and bounds.
This is a specialization of the more general new/1
@callback point_compare(a :: Interval.point(), b :: Interval.point()) :: :eq | :gt | :lt
Compare two points, returning if a == b
, a > b
or a < b
.
@callback point_format(point :: Interval.point()) :: String.t()
Return a string representation of a point for use in formatting intervals.
@callback point_normalize(point :: Interval.point()) :: :error | {:ok, Interval.point()}
Normalize a point to a canonical form. Returns :error if the point is invalid.
@callback point_parse(string :: String.t()) :: {:ok, Interval.point()} | :error
Parse a string representation of a point into a point, for use in parsing intervals.
@callback point_step(point :: Interval.point(), n :: integer()) :: Interval.point()
Step a discrete point n
steps.
If n
is negative, the point is stepped backwards.
For integers this is simply addition (point + n
)