Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jolin-io/isdef.jl
maintainable type inference
https://github.com/jolin-io/isdef.jl
julia julialang type-inference
Last synced: 2 months ago
JSON representation
maintainable type inference
- Host: GitHub
- URL: https://github.com/jolin-io/isdef.jl
- Owner: jolin-io
- License: mit
- Created: 2020-03-06T13:23:24.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2023-01-18T00:34:07.000Z (almost 2 years ago)
- Last Synced: 2024-11-09T08:03:16.924Z (2 months ago)
- Topics: julia, julialang, type-inference
- Language: Julia
- Homepage: https://jolin-io.github.io/IsDef.jl/stable
- Size: 367 KB
- Stars: 19
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# IsDef.jl
[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://jolin-io.github.io/IsDef.jl/stable)
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://jolin-io.github.io/IsDef.jl/dev)
[![Build Status](https://github.com/jolin-io/IsDef.jl/workflows/CI/badge.svg)](https://github.com/jolin-io/IsDef.jl/actions)
[![Coverage](https://codecov.io/gh/jolin-io/IsDef.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/jolin-io/IsDef.jl)This package provides primitives for dispatching on whether certain methods are implemented or not.
For installation or usage, open julia repl and run
```julia
using IsDef
```
which gives you access to following functions
- `isdef(f, arg1, arg2)::Bool` / `isdef(f, Arg1Type, Arg2Type)::Bool` checks whether a function is defined for the given types.If at least one of the arguments is not a type,
all arguments are automatically converted to types for you.- `Out(f, arg1, arg2)::ReturnType` / `Out(f, Arg1Type, Arg2Type)::ReturnType` returns the returntype of the given functioncall.
Note, that `Out` may return an abstract type that is wider than necessary, like e.g. `Any`.
If a functioncall is not defined, or predictably throws an error, `IsDef.NotApplicable` is returned.
`Out` is internally used by `isdef`.Internally of `Out(f, Arg1Type, Arg2Type)` a one-argument-version of `Out` is used which expects a single Tuple type, specifying the entire call signature. This is the heart of the `IsDef` package. For the example it would be
- `Out(Tuple{typeof(f), Arg1Type, Arg2Type})`If you want to specify inference of your method (output of `Out`), or whether it is defined (output of `isdef`), you need to overload this very one-argument method of `Out`. For the example it could be
- `Out(::Type{<:Tuple{typeof(f), Arg1Type, Arg2Type, Vararg}}) = ReturnType`Enjoy maintainable type inference.