Kwonly.jl

Macro to generate keyword-only version of a function
Author tkf
Popularity
2 Stars
Updated Last
2 Years Ago
Started In
March 2018

Kwonly.jl --- Macro to generate keyword-only version of a function

Build Status Coverage Status codecov.io

Basic Usage

Kwonly.jl provides a macro @add_kwonly. It creates a keyword-only version of the given function. Example:

using Kwonly

struct A
    x
    y
    @add_kwonly A(x, y=2) = new(x, y)
end

This macro add a keyword-only constructor by expanding A(x, y=2) = new(x, y) into:

A(x, y) = new(x, y)                                      # original
A(; x = throw(UndefKeywordError(:x)), y=2) = new(x, y)   # keyword-only

So, the struct A can also be constructed by using only keyword arguments:

@test A(1) == A(x=1)