InterfaceFunctions
Documentation for InterfaceFunctions.
InterfaceFunctions.UnimplementedInterface
InterfaceFunctions.gatherwheres
InterfaceFunctions.@interface
InterfaceFunctions.UnimplementedInterface
— TypeUnimplementedInterface <: Exception
Thrown when a subtype does not implement an obligatory interface.
InterfaceFunctions.gatherwheres
— Methodgatherwheres(ex)
Separate the function signature from the where
statement and return tuple of (function_call_signature, where_parameters_tuple)
Taken from MacroTools.jl
InterfaceFunctions.@interface
— Macro@interface fn_expr
Define an interface function for the abstract type in the first argument of the function signature in fn_expr
.
It is common to define empty functions for interfaces
function fn(a::A, b::B) end
This macro creates the function and adds an informative error message to the user so that he knows what went wrong and how to fix it.
@inteface fn(a::A, b::B)
roughly translates to
function fn(a::A, b::B)
throw(UnimplementedInterface{A}(#=signature=#))
end
An interface on an abstract type is a way to indicate that every subtype has to provide a custom method for this function. Interfaces are useful for code re-usability in higher order methods. Higher order methods of abstract types can use the interfaces defined on these types to provide implementations for their subtypes.