class Speculation::MergeSpec

@private

Constants

S

This is a Ruby translation of clojure.spec:

https://github.com/clojure/clojure/blob/master/src/clj/clojure/spec.clj

All credit belongs with Rich Hickey and contributors for their original work.


This is a Ruby translation of clojure.spec:

https://github.com/clojure/clojure/blob/master/src/clj/clojure/spec.clj

All credit belongs with Rich Hickey and contributors for their original work.


This is a Ruby translation of clojure.spec:

https://github.com/clojure/clojure/blob/master/src/clj/clojure/spec.clj

All credit belongs with Rich Hickey and contributors for their original work.


This is a Ruby translation of clojure.spec:

https://github.com/clojure/clojure/blob/master/src/clj/clojure/spec.clj

All credit belongs with Rich Hickey and contributors for their original work.


This is a Ruby translation of clojure.spec:

https://github.com/clojure/clojure/blob/master/src/clj/clojure/spec.clj

All credit belongs with Rich Hickey and contributors for their original work.

Public Class Methods

new(preds, gen = nil) click to toggle source
# File lib/speculation/spec/merge_spec.rb, line 13
def initialize(preds, gen = nil)
  @preds = preds
  @gen   = gen
end

Public Instance Methods

conform(x) click to toggle source
# File lib/speculation/spec/merge_spec.rb, line 18
def conform(x)
  ms = @preds.map { |pred| S.dt(pred, x) }

  if ms.any?(&S.method(:invalid?))
    :"Speculation/invalid"
  else
    ms.reduce(&:merge)
  end
end
explain(path, via, inn, x) click to toggle source
# File lib/speculation/spec/merge_spec.rb, line 32
def explain(path, via, inn, x)
  @preds.
    flat_map { |pred| S.explain1(pred, path, via, inn, x) }.
    compact
end
gen(overrides, path, rmap) click to toggle source
# File lib/speculation/spec/merge_spec.rb, line 42
def gen(overrides, path, rmap)
  return @gen.call if @gen

  gens = @preds.
    map { |pred| S.gensub(pred, overrides, path, rmap) }

  ->(r) do
    gens.map { |gen| gen.call(r) }.reduce(&:merge)
  end
end
unform(x) click to toggle source
# File lib/speculation/spec/merge_spec.rb, line 28
def unform(x)
  @preds.reverse.map { |pred| S.unform(pred, x) }.reduce(&:merge)
end
with_gen(gen) click to toggle source
# File lib/speculation/spec/merge_spec.rb, line 38
def with_gen(gen)
  self.class.new(@preds, gen)
end