Sha256: 66b350c571893d4cf7328040c2d27b5346aa8ca8f3be56b18b0d41852874f95a

Contents?: true

Size: 729 Bytes

Versions: 2

Compression:

Stored size: 729 Bytes

Contents

# frozen_string_literal: true

module Speculation
  # @private
  class AndSpec < Spec
    include NamespacedSymbols
    S = Speculation

    def initialize(preds)
      @preds = preds
      @specs = Concurrent::Delay.new do
        preds.map { |pred| S.send(:specize, pred) }
      end
    end

    def conform(value)
      @specs.value!.each do |spec|
        value = spec.conform(value)

        return S::INVALID if S.invalid?(value)
      end

      value
    end

    def explain(path, via, inn, value)
      S.explain_pred_list(@preds, path, via, inn, value)
    end

    def gen(overrides, path, rmap)
      if @gen
        @gen
      else
        S.gensub(@preds.first, overrides, path, rmap)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
speculation-0.3.1 lib/speculation/spec/and_spec.rb
speculation-0.3.0 lib/speculation/spec/and_spec.rb