Interval.Behaviour behaviour (Interval v2.0.1)

View Source

Defines 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 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

new_opt()

@type new_opt() ::
  {:left, Interval.point()} | {:right, Interval.point()} | {:bounds, String.t()}

new_opts()

@type new_opts() :: [new_opt()]

Callbacks

discrete?()

@callback discrete?() :: boolean()

Is this implementation of an interval considered discrete?

The interval is implicitly continuous if not discrete.

new(new_opts)

@callback new(new_opts()) :: Interval.t()

Create a new Interval.t/0

new(left, right, bounds)

@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

point_compare(a, b)

@callback point_compare(a :: Interval.point(), b :: Interval.point()) :: :eq | :gt | :lt

Compare two points, returning if a == b, a > b or a < b.

point_format(point)

(optional)
@callback point_format(point :: Interval.point()) :: String.t()

Return a string representation of a point for use in formatting intervals.

point_normalize(point)

@callback point_normalize(point :: Interval.point()) :: :error | {:ok, Interval.point()}

Normalize a point to a canonical form. Returns :error if the point is invalid.

point_parse(string)

(optional)
@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.

point_step(point, n)

@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)