lib/speculation/spec/merge_spec.rb in speculation-0.3.1 vs lib/speculation/spec/merge_spec.rb in speculation-0.4.0
- old
+ new
@@ -1,15 +1,20 @@
# frozen_string_literal: true
+# 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.
+
module Speculation
# @private
class MergeSpec < Spec
include NamespacedSymbols
S = Speculation
- def initialize(preds)
+ def initialize(preds, gen = nil)
@preds = preds
+ @gen = gen
end
def conform(x)
ms = @preds.map { |pred| S.dt(pred, x) }
@@ -22,9 +27,13 @@
def explain(path, via, inn, x)
@preds.
flat_map { |pred| S.explain1(pred, path, via, inn, x) }.
compact
+ end
+
+ def with_gen(gen)
+ self.class.new(@preds, gen)
end
def gen(overrides, path, rmap)
return @gen if @gen