Sha256: 489f87b31f9c5fe0d65eab0acb310fc4b8323b181e4de29ddb4bc26a739d33dd

Contents?: true

Size: 856 Bytes

Versions: 1

Compression:

Stored size: 856 Bytes

Contents

# frozen_string_literal: true

module Fear
  module Try
    # Try pattern matcher
    #
    # @note it has two optimized subclasses +Fear::Success::PatternMatch+ and +Fear::FailurePatternMatch+
    # @api private
    class PatternMatch < Fear::PatternMatch
      # Match against +Fear::Success+
      #
      # @param conditions [<#==>]
      # @return [Fear::Try::PatternMatch]
      def success(*conditions, &effect)
        branch = Fear.case(Fear::Success, &:get).and_then(Fear.case(*conditions, &effect))
        or_else(branch)
      end

      # Match against +Fear::Failure+
      #
      # @param conditions [<#==>]
      # @return [Fear::Try::PatternMatch]
      def failure(*conditions, &effect)
        branch = Fear.case(Fear::Failure, &:exception).and_then(Fear.case(*conditions, &effect))
        or_else(branch)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fear-3.0.0 lib/fear/try/pattern_match.rb