Giter Site home page Giter Site logo

namespacedenums.jl's Introduction

NamespacedEnums

Stable Dev Build Status

Important: Use SuperEnum Instead

I wrote this package assuming that nothing already existed that solved the problem. It turns out that SuperEnum does the same and more! Use that package instead.


If your module has a lot of enums, you might run into a few problems:

  • Your module's namespace becomes polluted with loads of names
  • You can't use the same name for two different enums
  • You can't tell which enum a value belongs to
  • Tab completion is not helpful for finding instances of a certain enum

NamespacedEnums' @nsenum works similarly a regular Enum, but its values are hidden behind a module. To access the values, use EnumName.value1. To access the enum itself, use EnumName.T.

julia> using NamespacedEnums

julia> @nsenum Fruit apple=1 orange=2 kiwi=3;

julia> f(x::Fruit.T) = "I'm a Fruit with value: \$(Int(x))";

julia> f(apple)
ERROR: UndefVarError: apple not defined

julia> f(Fruit.apple)
"I'm a Fruit with value: 1"

namespacedenums.jl's People

Contributors

christopher-dg avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

namespacedenums.jl's Issues

`instances` & instantiate by indices no longer works

@nsenum Fruit apple=1 orange=2 kiwi=3;

julia> Fruit(1)
ERROR: MethodError: objects of type Module are not callable
Stacktrace:
 [1] top-level scope at REPL[13]:1

julia> instances(Fruit)
ERROR: MethodError: no method matching instances(::Module)
Closest candidates are:
  instances(::Type{Base.MPFR.MPFRRoundingMode}) at Enums.jl:193
  instances(::Type{LibGit2.Consts.OBJECT}) at Enums.jl:193
  instances(::Type{LibGit2.Consts.DELTA_STATUS}) at Enums.jl:193
  ...
Stacktrace:
 [1] top-level scope at REPL[14]:1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.