Sha256: 63b9459381edb9d4f89c5c858cd2ee22a53e8e952e3193247d17d817bd5d98f4
Contents?: true
Size: 1.66 KB
Versions: 1
Compression:
Stored size: 1.66 KB
Contents
# frozen_string_literal: true module Speculation # @private class TupleSpec < SpecImpl include NamespacedSymbols S = Speculation def initialize(preds) @preds = preds @delayed_specs = Concurrent::Delay.new do preds.map { |pred| S.send(:specize, pred) } end end def conform(collection) specs = @delayed_specs.value! unless Utils.array?(collection) && collection.count == specs.count return ns(S, :invalid) end return_value = collection.class.new collection.zip(specs).each do |(value, spec)| conformed_value = spec.conform(value) if S.invalid?(conformed_value) return ns(S, :invalid) else return_value += [conformed_value] end end return_value end def explain(path, via, inn, value) if !Utils.array?(value) [{ :path => path, :val => value, :via => via, :in => inn, :pred => [Utils.method(:array?), [value]] }] elsif @preds.count != value.count [{ :path => path, :val => value, :via => via, :in => inn, :pred => [Utils.method(:count_eq), [@preds, value.count]] }] else probs = @preds.zip(value).each_with_index.flat_map { |(pred, x), index| unless S.pvalid?(pred, x) S.explain1(pred, Utils.conj(path, index), via, Utils.conj(inn, index), x) end } probs.compact end end def gen(overrides, path, rmap) return @gen if @gen gens = @preds.each_with_index. map { |p, i| S.gensub(p, overrides, Utils.conj(path, i), rmap) } ->(rantly) do gens.map { |g| g.call(rantly) } end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
speculation-0.2.0 | lib/speculation/spec_impl/tuple_spec.rb |