Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Can do or not? It's easy. Seehttps://tk3369.github.io/BinaryTraits.jl/dev/

License

NotificationsYou must be signed in to change notification settings

tk3369/BinaryTraits.jl

Repository files navigation

Dev DocsBuild Statuscodecov.ioProject Status

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.

Motivation

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"

Main Features

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

Credits

  • 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

Related Projects

There are quite a few traits libraries around. If this package isn't foryou, take a look at these others:


[8]ページ先頭

©2009-2025 Movatter.jp