Arrays.Behaviour behaviour (Arrays v1.1.0) View Source

This module specifies the behaviour that all array-types should implement.

Adding a new Array type is done by implementing Arrays.Protocol. However, Elixir protocols require the first argument to a function to be a value of the type that the protocol is implemented for.

This is a problem for empty, as it does not take such value as first argument: it is used to construct such a value in the first place!

This means that besides implementing Arrays.Protocol, types should also add @behaviour Arrays.Behaviour to their module, and add a sensible definition for empty/1.

Link to this section Summary

Types

Option passed to empty/1.

A list of options passed to empty/1

Callbacks

Should create a new instance of your custom array type.

Link to this section Types

Specs

option() :: {:default, any()} | {atom(), any()}

Option passed to empty/1.

The option :default is recognized by all array implementations. A particular array implementation might recognize other specialized options.

Specs

options() :: [option()]

A list of options passed to empty/1

Link to this section Callbacks

Specs

empty(options()) :: Arrays.Protocol.t()

Should create a new instance of your custom array type.

This is called internally by functions such as Arrays.new/0 and Arrays.empty/1.