https://github.com/tkf/kwonly.jl
Macro to generate keyword-only version of a function
https://github.com/tkf/kwonly.jl
Last synced: 7 months ago
JSON representation
Macro to generate keyword-only version of a function
- Host: GitHub
- URL: https://github.com/tkf/kwonly.jl
- Owner: tkf
- License: other
- Created: 2018-03-11T07:22:18.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-02-10T08:48:37.000Z (almost 6 years ago)
- Last Synced: 2025-01-20T19:44:37.332Z (12 months ago)
- Language: Julia
- Size: 25.4 KB
- Stars: 3
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Kwonly.jl --- Macro to generate keyword-only version of a function
[![Build Status][travis-img]][travis-url]
[![Coverage Status][coveralls-img]][coveralls-url]
[![codecov.io][codecov-img]][codecov-url]
## Basic Usage
Kwonly.jl provides a macro `@add_kwonly`. It creates a keyword-only
version of the given function. Example:
```julia
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:
```julia
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:
```julia
@test A(1) == A(x=1)
```
[travis-img]: https://travis-ci.org/tkf/Kwonly.jl.svg?branch=master
[travis-url]: https://travis-ci.org/tkf/Kwonly.jl
[coveralls-img]: https://coveralls.io/repos/tkf/Kwonly.jl/badge.svg?branch=master&service=github
[coveralls-url]: https://coveralls.io/github/tkf/Kwonly.jl?branch=master
[codecov-img]: http://codecov.io/github/tkf/Kwonly.jl/coverage.svg?branch=master
[codecov-url]: http://codecov.io/github/tkf/Kwonly.jl?branch=master