Type.Helpers behaviour (mavis v0.0.6) View Source

Link to this section Summary

Functions

Wraps the Type.Helpers.group_compare/2 function headers in a common prologue. This prevents errors from being made in code that must be common to all types.

Wraps the Type.Properties.intersection/2 function headers in a common prologue. This prevents errors from being made in code that must be common to all types.

Wraps the Type.Properties.subtype?/2 function headers in a common prologue. This prevents errors from being made in code that must be common to all types.

Wraps the Type.Properties.usable_as/3 function headers in common prologue and fallback clauses. This prevents errors from being made in code that must be common to all types.

Callbacks

Type modules should implement this function to perform comparisons against all other types in their type group.

Link to this section Functions

Link to this macro

group_compare(list)

View Source (macro)

Wraps the Type.Helpers.group_compare/2 function headers in a common prologue. This prevents errors from being made in code that must be common to all types.

Prologue function matches:

  • matches identical types and reports equality
  • matches String.t/0 special case (only for Type.Bitstring)
  • compares union types and puts them in
  • compares opaque types
  • compares function var types
Link to this macro

intersection(list)

View Source (macro)

Wraps the Type.Properties.intersection/2 function headers in a common prologue. This prevents errors from being made in code that must be common to all types.

Prologue function matches:

  • matches itself and returns itself
  • matches any/0 and returns itself
  • calculates intersections for remote types
  • intersects union types
  • intersects function var types

Wraps the Type.Properties.subtype?/2 function headers in a common prologue. This prevents errors from being made in code that must be common to all types.

Prologue function matches:

  • matches itself and returns true
  • matches none/0 and returns false
  • matches any/0 and returns any
  • calculates intersections for remote types
  • intersects union types
  • intersects function var types

can also take :usable_as as an argument; this declares that subtype?/2 is equivalent to an :ok response from Type.usable_as/3.

Link to this macro

usable_as(list)

View Source (macro)

Wraps the Type.Properties.usable_as/3 function headers in common prologue and fallback clauses. This prevents errors from being made in code that must be common to all types.

Prologue function matches:

  • matches equal types and makes them output :ok
  • matches usable_as with any() and makes them output :ok

Fallback function matches:

  • catches usable_as against unions; and performs the appropriate attempt to match into each of the union's subtypes.
  • catches all other attempts to run usable_as, and returns {:error, metadata}

Link to this section Callbacks

Link to this callback

group_compare(arg1, arg2)

View Source

Specs

group_compare(Type.t(), Type.t()) :: :lt | :gt | :eq

Type modules should implement this function to perform comparisons against all other types in their type group.

See Type.typegroup/1