Replace KeywordDispatch for an in-house implementation #272
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
KeywordDispatch.jl is no longer actively developed and doesn't propagate docs. With our own implementation of keyword-dispatching, we have more control over it and can fix the propagation of docs.
The idea is to do sth as
Core.kwcall
; i.e. Julia lowers calls to methods with keyword-arguments to calls toCore.kwcall
where the 1st argument is aNamedTuple
with the arguments, the 2nd argument is the type of the function and the rest are the positional arguments. In our case, we call thatkwcall
manually on the default method without akwcall
function (but I can reconsider), so we implement keyword-dispatched methods as a method of the same function but where the kwargs are aNamedTuple
that is passed as the first argument.For example, for
inds
, the replacement for@kwdispatch
isThe default
@kwmethod
is replaced forAnd the
set
-kwarg method is nowIt looks a lil more verbose than before, but we can add some helpers. The nice thing is that we can now put docstrings to these keyword-methods and also point to them.
Note:
sort_nt
is a function that sorts the keys of aNamedTuple
. It's used for making keyword-dispatch invariant to kwarg order.