Sha256: 216eaf9bef7ded97f992edfcbb8f2627fb39fcbfb0ff5db47a8b6a0ea55e65d5
Contents?: true
Size: 778 Bytes
Versions: 1
Compression:
Stored size: 778 Bytes
Contents
# frozen_string_literal: true module Kind class Result::Success < Result::Monad DEFAULT_TYPE = :ok def success? true end def value_or(_default = UNDEFINED, &block) @value end def map(&fn) map!(&fn) rescue Kind::Monad::Error => e raise e rescue StandardError => e Result::Failure[:exception, e] end def map!(&fn) monad = fn.call(@value) return monad if Result::Monad === monad raise Kind::Monad::Error.new('Kind::Success | Kind::Failure', monad) end alias_method :then, :map alias_method :then!, :map! alias_method :and_then, :map alias_method :and_then!, :map! def inspect '#<%s type=%p value=%p>' % ['Kind::Success', type, value] end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
kind-5.2.0 | lib/kind/result/success.rb |