- Notifications
You must be signed in to change notification settings - Fork3
Can do or not? It's easy. Seehttps://tk3369.github.io/BinaryTraits.jl/dev/
License
tk3369/BinaryTraits.jl
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
BinaryTraits focuses on usability - traits should be simple to understand and easy to use.For that reason, every trait is binary. An object either has the trait (positive) or does nothave the trait (negative).
The design is heavily influenced by the Holy Traits pattern as explained in myHoly Traits book excerptas well as in Julia manual'strait-based dispatch section.If you think about Holy Traits as the powerful manual transmission, then BinaryTraitsgives you automatic transmission. The machinery is the same but it is a lot more pleasantto use.
NOTE: This package is under active development and we may introduce breakingchanges. Please follow theissues listif you would like to contribute to the project or have a stake inthe design.
Just a quick example below. More details can be foundin ourdocumentation.
# Use package and import desired positive/negative trait type aliasesusing BinaryTraitsusing BinaryTraits.Prefix: Can# Define a trait and its interface contracts@trait Fly@implement Can{Fly} byfly(_, destination::Location, speed::Float64)# Define your data type and implementationstruct Birdendfly(::Bird, destination::Location, speed::Float64)="Wohoo! Arrived! 🐦"# Assign your data type to a trait@assign Bird with Can{Fly}# Verify that your implementation is correct@check(Bird)# Dispatch for all flying things@traitfnflap(::Can{Fly}, freq::Float64)="Flapping wings at$freq Hz"
Current features are listed below. Additional features are planned andlogged in the issues list.
- Define traits and assigning them to your own data types
- Define composite traits that exhibits all of the underlying traits
- Define interface contracts required for a trait
- Verify that your data type fully implements all interface contracts
- Define traits/interfaces in one module and use them from another module
- Define trait dispatch functions easily
- Klaus Crusius for his ideas, articulation, and significant contributions to this project
- Jānis Erdmanis for his proposal of a new design based upon parametric types
There are quite a few traits libraries around. If this package isn't foryou, take a look at these others:
About
Can do or not? It's easy. Seehttps://tk3369.github.io/BinaryTraits.jl/dev/