diff options
| author | teddywing | 2017-08-01 17:54:02 +0200 |
|---|---|---|
| committer | GitHub | 2017-08-01 17:54:02 +0200 |
| commit | 8774b48a41779248d58c78eb305ce1c579c82708 (patch) | |
| tree | 4fb5b465225565b258ecb5e62c0e965637cf052c /lib | |
| parent | 84d73a0b872b078ae5b73e2f8f2db2bb304622c2 (diff) | |
| parent | 1f09ead58c9c603e9d767781ceb82859b2393f49 (diff) | |
| download | chouette-core-8774b48a41779248d58c78eb305ce1c579c82708.tar.bz2 | |
Merge pull request #48 from af83/1726-WorkbenchImport-for-multi-Netex-import
1726 workbench import for multi netex import
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/result.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/result.rb b/lib/result.rb new file mode 100644 index 000000000..96e03d323 --- /dev/null +++ b/lib/result.rb @@ -0,0 +1,37 @@ +# A value wrapper adding status information to any value +# Status can be :ok or :error, we are thusly implementing +# what is expressed in Elixir/Erlang as result tuples and +# in Haskell as `Data.Either` +class Result + + attr_reader :status, :value + + class << self + def ok value + make :ok, value + end + def error value + make :error, value + end + + def new *args + raise NoMethodError, "No default constructor for #{self}" + end + + private + def make status, value + allocate.tap do | o | + o.instance_exec do + @status = status + @value = value + end + end + end + end + + def ok?; status == :ok end + + def == other + other.kind_of?(self.class) && other.status == status && other.value == value + end +end |
