Skip to content

Commit

Permalink
fix: included and extend Methods
Browse files Browse the repository at this point in the history
  • Loading branch information
thadeu committed May 7, 2024
1 parent e2c399c commit d88f9ad
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions lib/zx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,29 @@
require 'zx/result'

module Zx
Success = ->(value = nil, options = {}) { Zx.Success(value, { type: :ok }.merge(options)) }
Failure = ->(value = nil, options = {}) { Zx.Failure(value, { type: :error }.merge(options)) }

def Success(value = nil, options = {})
Zx::Result.new.success!(value, type: options.fetch(:type, :ok))
end

def Failure(value = nil, options = {})
Zx::Result.new.failure!(value, type: options.fetch(:type, :error))
end

def Try(default = nil, options = {})
Success[yield]
rescue StandardError => e
Failure[default || options.fetch(:or, nil)]
end

def Given(input)
Try { input }
module Methods
Success = ->(value = nil, options = {}) { Zx.Success(value, { type: :ok }.merge(options)) }
Failure = ->(value = nil, options = {}) { Zx.Failure(value, { type: :error }.merge(options)) }

def Success(value = nil, options = {})
Zx::Result.new.success!(value, type: options.fetch(:type, :ok))
end

def Failure(value = nil, options = {})
Zx::Result.new.failure!(value, type: options.fetch(:type, :error))
end

def Try(default = nil, options = {})
Success[yield]
rescue StandardError => e
Failure[default || options.fetch(:or, nil)]
end

def Given(input)
Try { input }
end
end

include Methods
extend Methods
end

0 comments on commit d88f9ad

Please sign in to comment.