Seelengrab / RequiredInterfaces.jl

A small package for providing the minimal required method surface of a Julia API
https://seelengrab.github.io/RequiredInterfaces.jl/
MIT License
38 stars 1 forks source link

Requiring several functions? #1

Closed gdalle closed 1 year ago

gdalle commented 1 year ago

Awesome package, it's simple enough to use that I wanna give it a test run in HMMs.jl!

Small question: how does one specify that multiple functions are part of the interface? My two best guesses are

@required T f(::T) g(::T)

or

@required T f(::T)
@required T g(::T)

Judging by the code I'm leaning towards option 2 but I'm not a macro expert. Also, it may be cool to allow option 1?

Seelengrab commented 1 year ago

Yes, option two is currently the only way. I haven't thought about making option one work, but I'm a bit hesitant to add that because I think the lines are going to get very long very quick; especially with a bit longer function names and more than one argument. The general idea is to pair the interface requirement with the docstring, which I sadly couldn't easily make work in the macro itself (docstring lowering is a bit weird). I'll have to add an example to the docs showing how to do that better :thinking:

Adding an example with more than one function would be good though!

Seelengrab commented 1 year ago

Would something like

@required MyInterface begin
    f(...)
    g(...)
end

Work for you?

gdalle commented 1 year ago

Yes that's perfect :)