Class: MonadOxide::None
Overview
‘None’ represents the absence of a value in an ‘Option’.
Any methods in Option that would process a present value (Some) will fall through with None instances.
Instance Method Summary collapse
-
#and_then(f = nil) { ... } ⇒ None
Falls through.
-
#initialize ⇒ None
constructor
Create a None.
-
#inspect_none(f = nil) { ... } ⇒ Option
Applies ‘f’ or the block and returns the same ‘None’.
-
#inspect_some(f = nil) { ... } ⇒ None
Falls through.
-
#map(f = nil) { ... } ⇒ None
Falls through.
-
#map_none(f = nil) { ... } ⇒ Option<B>
Applies ‘f’ or the block and returns a new ‘Option’ with the returned value.
-
#none? ⇒ Boolean
Identifies that this is a ‘None’.
-
#or_else(f = nil) { ... } ⇒ Some<B> | None
Invokes ‘f’ or the block and returns the Option returned from that.
-
#some? ⇒ Boolean
Identifies that this is not a ‘Some’.
-
#unwrap ⇒ A
Dangerously try to access the ‘Option’ data.
-
#unwrap_none ⇒ nil
Dangerously access the ‘None’ data.
Methods inherited from Option
Constructor Details
Instance Method Details
#and_then(f = nil) { ... } ⇒ None
Falls through. @see Option#and_then for how this is handled in either Option case, and @see Some#and_then for how this is handled in the Some case.
26 27 28 |
# File 'lib/none.rb', line 26 def and_then(f=nil, &block) self end |
#inspect_none(f = nil) { ... } ⇒ Option
Applies ‘f’ or the block and returns the same ‘None’. No changes are applied. This is ideal for logging.
49 50 51 52 |
# File 'lib/none.rb', line 49 def inspect_none(f=nil, &block) (f || block).call() self end |
#inspect_some(f = nil) { ... } ⇒ None
Falls through. @see Option#inspect_some for how this is handled in either Option case, and @see Some#inspect_some for how this is handled in the Some case.
37 38 39 |
# File 'lib/none.rb', line 37 def inspect_some(f=nil, &block) self end |
#map(f = nil) { ... } ⇒ None
Falls through. @see Option#map for how this is handled in either Option case, and @see Some#map for how this is handled in the Some case.
61 62 63 |
# File 'lib/none.rb', line 61 def map(f=nil, &block) self end |
#map_none(f = nil) { ... } ⇒ Option<B>
Applies ‘f’ or the block and returns a new ‘Option’ with the returned value.
74 75 76 |
# File 'lib/none.rb', line 74 def map_none(f=nil, &block) Some.new((f || block).call()) end |
#none? ⇒ Boolean
Identifies that this is a ‘None’. For counterparts:
85 86 87 |
# File 'lib/none.rb', line 85 def none?() true end |
#or_else(f = nil) { ... } ⇒ Some<B> | None
Invokes ‘f’ or the block and returns the Option returned from that. The return type is enforced.
99 100 101 102 103 104 105 106 |
# File 'lib/none.rb', line 99 def or_else(f=nil, &block) option = (f || block).call() if !option.kind_of?(Option) raise OptionReturnExpectedError.new(option) else option end end |
#some? ⇒ Boolean
Identifies that this is not a ‘Some’. For counterparts:
115 116 117 |
# File 'lib/none.rb', line 115 def some?() false end |
#unwrap ⇒ A
Dangerously try to access the ‘Option’ data. If this is a ‘None’, an exception will be raised. It is recommended to use this for tests only.
123 124 125 126 127 |
# File 'lib/none.rb', line 123 def unwrap() raise UnwrapError.new( "#{self.class} could not be unwrapped as a Some.", ) end |
#unwrap_none ⇒ nil
Dangerously access the ‘None’ data. If this is a ‘Some’, an exception will be raised. It is recommended to use this for tests only.
133 134 135 |
# File 'lib/none.rb', line 133 def unwrap_none() nil end |