Advanced
Here's an example of a multi-argument interface where we implement groups. For mathematicians, a group is just a set of objects where you can perform multiplication
and inversion
, such that an element multiplied by its inverse yields a neutral
element.
This functionality is still experimental and might evolve in the future. If you have feedback about it, open an issue to help us improve it!
using Interfaces
Definition
Unlike the AnimalInterface
, this example involves functions with more than one argument. Such arguments need to be passed to the interface testing code, which means the interface definition must take them into account as well.
For technical reasons, we provide a type called Arguments
that you should use for this purpose. It behaves exactly like a NamedTuple
but enables easier dispatch.
module Group
+Advanced · Interfaces.jl Advanced
Here's an example of a multi-argument interface where we implement groups. For mathematicians, a group is just a set of objects where you can perform multiplication
and inversion
, such that an element multiplied by its inverse yields a neutral
element.
Warning This functionality is still experimental and might evolve in the future. If you have feedback about it, open an issue to help us improve it!
using Interfaces
Definition
Unlike the AnimalInterface
, this example involves functions with more than one argument. Such arguments need to be passed to the interface testing code, which means the interface definition must take them into account as well.
For technical reasons, we provide a type called Arguments
that you should use for this purpose. It behaves exactly like a NamedTuple
but enables easier dispatch.
module Group
using Interfaces
@@ -36,4 +36,4 @@
Interfaces.test(Group.GroupInterface, Float64, int_pairs)
catch e
print(e.msg)
-end
Each tested object must either be an instance of `Float64` or an instance of `Arguments` whose field types include at least one subtype of `Float64`. You provided a `Arguments{(:x, :y), Tuple{Int64, Int64}}` instead.
In summary, there are two things to remember:
- The anonymous functions in the interface conditions of
Interfaces.@interface
should accept a single object of type Arguments
and then work with its named fields. These fields should be listed in the docstring. - The list of objects passed to
Interface.test
must all be of type Arguments
, with the right named fields. At least one field must have the type you are testing.
This page was generated using Literate.jl.
Settings
This document was generated with Documenter.jl version 1.4.1 on Sunday 16 June 2024. Using Julia version 1.10.4.
+end
Each tested object must either be an instance of `Float64` or an instance of `Arguments` whose field types include at least one subtype of `Float64`. You provided a `Arguments{(:x, :y), Tuple{Int64, Int64}}` instead.
In summary, there are two things to remember:
- The anonymous functions in the interface conditions of
Interfaces.@interface
should accept a single object of typeArguments
and then work with its named fields. These fields should be listed in the docstring. - The list of objects passed to
Interface.test
must all be of typeArguments
, with the right named fields. At least one field must have the type you are testing.
This page was generated using Literate.jl.