Created
September 28, 2016 04:25
-
-
Save bitmage/8cfb434625e0b66b34c8ceb2999428d4 to your computer and use it in GitHub Desktop.
enumeration example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Base.== | |
import Base.convert | |
sources = Set([:given, :self, :old, :neighbor]) | |
immutable Source | |
s | |
Source(s) = in(s, sources) ? new(s) : error("Invalid source: $(s). Valid options are: $(sources)") | |
end | |
==(l::Source, r::Source) = l.s == r.s | |
convert(::Source, s::Symbol) = Source(s) | |
convert(Source, :given) | |
# => MethodError: Cannot `convert` an object of type Symbol to an object of type Source |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment