lib/mangrove/option.rb in mangrove-0.1.0 vs lib/mangrove/option.rb in mangrove-0.2.0
- old
+ new
@@ -44,20 +44,36 @@
# T.absurd(other)
false
end
end
+ sig { returns(InnerType) }
+ def unwrap
+ @inner
+ end
+
+ sig { override.params(_default: InnerType).returns(InnerType) }
+ def unwrap_or(_default)
+ @inner
+ end
+
sig { override.returns(InnerType) }
def unwrap!
@inner
end
sig { override.params(_message: String).returns(InnerType) }
def expect!(_message)
@inner
end
+ sig { override.returns(T::Boolean) }
+ def some? = true
+
+ sig { override.returns(T::Boolean) }
+ def none? = false
+
sig { override.params(block: T.proc.params(inner: InnerType).returns(Option[InnerType])).returns(Option[InnerType]) }
def map_some(&block)
block.call(@inner)
end
@@ -93,20 +109,31 @@
false
# T.absurd(other)
end
end
+ sig { override.params(default: InnerType).returns(InnerType) }
+ def unwrap_or(default)
+ default
+ end
+
sig { override.returns(InnerType) }
def unwrap!
raise Option::ControlSignal, Result::Err.new("called `Option#unwrap!` on an `None` value: #{self}")
end
sig { override.params(message: String).returns(InnerType) }
def expect!(message)
raise Option::ControlSignal, Result::Err.new(message)
end
+ sig { override.returns(T::Boolean) }
+ def some? = false
+
+ sig { override.returns(T::Boolean) }
+ def none? = true
+
sig { override.params(_block: T.proc.params(inner: InnerType).returns(Option[InnerType])).returns(Option::None[InnerType]) }
def map_some(&_block)
self
end
@@ -117,14 +144,23 @@
end
sig { abstract.params(other: BasicObject).returns(T::Boolean) }
def ==(other); end
+ sig { abstract.params(default: InnerType).returns(InnerType) }
+ def unwrap_or(default); end
+
sig { abstract.returns(InnerType) }
def unwrap!; end
sig { abstract.params(message: String).returns(InnerType) }
def expect!(message); end
+
+ sig { abstract.returns(T::Boolean) }
+ def some?; end
+
+ sig { abstract.returns(T::Boolean) }
+ def none?; end
sig { abstract.params(block: T.proc.params(inner: InnerType).returns(Option[InnerType])).returns(Option[InnerType]) }
def map_some(&block); end
sig { abstract.params(block: T.proc.returns(Option[InnerType])).returns(Option[InnerType]) }