File: value/core/union/result.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Umu#6
  module: Value#8
  module: Core#10
has properties
function: make_ok / 1 #123
function: make_err / 1 #130
  module: Union#12
  module: Result#14
  class: Abstract#16
inherits from
  Abstract ( Umu::Value::Core::Union )
has properties
class method: base_type_sym #17
attribute: contents [R] #22
method: initialize / 1 #24
method: meth_is_ok / 3 #38
method: meth_is_err / 3 #48
  class: Ok#56
inherits from
  Abstract ( Umu::Value::Core::Union::Result )
has properties
class method: order_num #57
class method: meth_make / 4 #67
method: meth_is_ok / 3 #79
  class: Err#87
inherits from
  Abstract ( Umu::Value::Core::Union::Result )
has properties
class method: order_num #88
class method: meth_make / 4 #98
method: meth_is_err / 3 #110

Class Hierarchy

Code

   1  # coding: utf-8
   2  # frozen_string_literal: true
   3 
   4 
   5 
   6  module Umu
   7 
   8  module Value
   9 
  10  module Core
  11 
  12  module Union
  13 
  14  module Result
  15 
  16  class Abstract < Union::Abstract
  17      def self.base_type_sym
  18          :Option
  19      end
  20 
  21 
  22      attr_reader :contents
  23 
  24      def initialize(contents)
  25          ASSERT.kind_of contents, VC::Top
  26 
  27          super()
  28 
  29          @contents = contents
  30      end
  31 
  32 
  33      define_instance_method(
  34          :meth_is_ok,
  35          :Ok?, [],
  36          [], VCA::Bool
  37      )
  38      def meth_is_ok(_loc, _env, event)
  39          VC.make_false
  40      end
  41 
  42 
  43      define_instance_method(
  44          :meth_is_err,
  45          :Err?, [],
  46          [], VCA::Bool
  47      )
  48      def meth_is_err(_loc, _env, event)
  49          VC.make_false
  50      end
  51  end
  52  Abstract.freeze
  53 
  54 
  55 
  56  class Ok < Abstract
  57      def self.order_num
  58          __LINE__
  59      end
  60 
  61 
  62      define_class_method(
  63          :meth_make,
  64          :make, [],
  65          [VC::Top], self
  66      )
  67      def self.meth_make(_loc, _env, _event, contents)
  68          ASSERT.kind_of contents, VC::Top
  69 
  70          VC.make_ok contents
  71      end
  72 
  73 
  74      define_instance_method(
  75          :meth_is_ok,
  76          :Ok?, [],
  77          [], VCA::Bool
  78      )
  79      def meth_is_ok(_loc, _env, _event)
  80          VC.make_true
  81      end
  82  end
  83  Ok.freeze
  84 
  85 
  86 
  87  class Err < Abstract
  88      def self.order_num
  89          __LINE__
  90      end
  91 
  92 
  93      define_class_method(
  94          :meth_make,
  95          :make, [],
  96          [VC::Top], self
  97      )
  98      def self.meth_make(_loc, _env, _event, contents)
  99          ASSERT.kind_of contents, VC::Top
 100 
 101          VC.make_err contents
 102      end
 103 
 104 
 105      define_instance_method(
 106          :meth_is_err,
 107          :Err?, [],
 108          [], VCA::Bool
 109      )
 110      def meth_is_err(_loc, _env, event)
 111          VC.make_true
 112      end
 113  end
 114  Err.freeze
 115 
 116  end # Umu::Value::Core::Union::Result
 117 
 118  end # Umu::Value::Core::Union
 119 
 120 
 121  module_function
 122 
 123      def make_ok(contents)
 124          ASSERT.kind_of contents, VC::Top
 125 
 126          Union::Result::Ok.new(contents).freeze
 127      end
 128 
 129 
 130      def make_err(contents)
 131          ASSERT.kind_of contents, VC::Top
 132 
 133          Union::Result::Err.new(contents).freeze
 134      end
 135 
 136  end # Umu::Value::Core
 137 
 138  end # Umu::Value
 139 
 140  end # Umu