File: value/core/union/option.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_none #151
function: make_some / 1 #156
  module: Union#12
  module: Option#14
has properties
constant: NONE #94
  class: Abstract#16
inherits from
  Abstract ( Umu::Value::Core::Union )
has properties
class method: base_type_sym #17
method: none? #22
method: some? #27
method: meth_is_none / 3 #37
method: meth_is_some / 3 #47
  class: None#62
inherits from
  Abstract ( Umu::Value::Core::Union::Option )
has properties
class method: order_num #63
class method: meth_make / 3 #73
method: none? #78
method: meth_is_none / 3 #88
  class: Some#98
inherits from
  Abstract ( Umu::Value::Core::Union::Option )
has properties
class method: order_num #99
class method: meth_make / 4 #109
attribute: contents [R] #116
method: initialize / 1 #119
method: some? #128
method: meth_is_some / 3 #138

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 Option
  15 
  16  class Abstract < Union::Abstract
  17      def self.base_type_sym
  18          :Option
  19      end
  20 
  21 
  22      def none?
  23          false
  24      end
  25 
  26 
  27      def some?
  28          false
  29      end
  30 
  31 
  32      define_instance_method(
  33          :meth_is_none,
  34          :None?, [],
  35          [], VCA::Bool
  36      )
  37      def meth_is_none(_loc, _env, event)
  38          VC.make_false
  39      end
  40 
  41 
  42      define_instance_method(
  43          :meth_is_some,
  44          :Some?, [],
  45          [], VCA::Bool
  46      )
  47      def meth_is_some(_loc, _env, event)
  48          VC.make_false
  49      end
  50 
  51 
  52      define_instance_method(
  53          :meth_is_less_than,
  54          :'<', [],
  55          [self], VCA::Bool
  56      )
  57  end
  58  Abstract.freeze
  59 
  60 
  61 
  62  class None < Abstract
  63      def self.order_num
  64          __LINE__
  65      end
  66 
  67 
  68      define_class_method(
  69          :meth_make,
  70          :make, [],
  71          [], self
  72      )
  73      def self.meth_make(_loc, _env, _event)
  74          VC.make_none
  75      end
  76 
  77 
  78      def none?
  79          true
  80      end
  81 
  82 
  83      define_instance_method(
  84          :meth_is_none,
  85          :None?, [],
  86          [], VCA::Bool
  87      )
  88      def meth_is_none(_loc, _env, _event)
  89          VC.make_true
  90      end
  91  end
  92  None.freeze
  93 
  94  NONE = None.new.freeze
  95 
  96 
  97 
  98  class Some < Abstract
  99      def self.order_num
 100          __LINE__
 101      end
 102 
 103 
 104      define_class_method(
 105          :meth_make,
 106          :make, [],
 107          [VC::Top], self
 108      )
 109      def self.meth_make(_loc, _env, _event, contents)
 110          ASSERT.kind_of contents, VC::Top
 111 
 112          VC.make_some contents
 113      end
 114 
 115 
 116      attr_reader :contents
 117 
 118 
 119      def initialize(contents)
 120          ASSERT.kind_of contents, VC::Top
 121 
 122          super()
 123 
 124          @contents = contents
 125      end
 126 
 127 
 128      def some?
 129          true
 130      end
 131 
 132 
 133      define_instance_method(
 134          :meth_is_some,
 135          :Some?, [],
 136          [], VCA::Bool
 137      )
 138      def meth_is_some(_loc, _env, event)
 139          VC.make_true
 140      end
 141  end
 142  Some.freeze
 143 
 144  end # Umu::Value::Core::Union::Option
 145 
 146  end # Umu::Value::Core::Union
 147 
 148 
 149  module_function
 150 
 151      def make_none
 152          Union::Option::NONE
 153      end
 154 
 155 
 156      def make_some(contents)
 157          ASSERT.kind_of contents, VC::Top
 158 
 159          Union::Option::Some.new(contents).freeze
 160      end
 161 
 162  end # Umu::Value::Core
 163 
 164  end # Umu::Value
 165 
 166  end # Umu