lib/zx/result.rb in zx-result-0.0.1 vs lib/zx/result.rb in zx-result-0.0.2
- old
+ new
@@ -69,19 +69,29 @@
def then(&block)
fmap(&block)
end
+ def step(&block)
+ fmap(&block)
+ end
+
def fmap(&block)
return self if failure?
new_value = block.call @value
@value = new_value
self
end
+ def check(&block)
+ return self if !!block.call(@value)
+
+ failure!
+ end
+
def failure!(value = nil, type: :error)
@type = type.to_sym
@success = false
@value = value
@@ -104,18 +114,18 @@
private :__execute__
def Success(value = nil, options = {})
success!(value, type: options.fetch(:type, :ok))
end
-
+
def Success!(value = nil, options = {})
success!(value, type: options.fetch(:type, :ok))
end
def Failure(value = nil, options = {})
failure!(value, type: options.fetch(:type, :error))
end
-
+
def Failure!(value = nil, options = {})
failure!(value, type: options.fetch(:type, :error))
end
def self.Success(value = nil, options = {})