Sha256: a2750e594b95805efb5b288eebd12def055878e335716bd39f132f03712efe23
Contents?: true
Size: 1020 Bytes
Versions: 1
Compression:
Stored size: 1020 Bytes
Contents
# frozen_string_literal: true module BCDD::Contract module Unit::Checker include Core::Checker SequenceMapper = ->(strategy1, strategy2) do ->(value, err) do strategy1.call(value, err) return unless err.empty? strategy2.call(value, err) end end def &(other) compose(other, SequenceMapper) end ParallelMapper = ->(strategy1, strategy2) do ->(value, err) do err1 = [] err2 = [] strategy1.call(value, err1) strategy2.call(value, err2) return if err1.empty? || err2.empty? err << err1.concat(err2).map { |msg| format(msg, value) }.join(' OR ') end end def |(other) compose(other, ParallelMapper) end private def compose(other, mapper) other = Unit::Factory.build(other) composed_strategy = mapper.call(strategy, other.strategy) Unit::Factory.new(composed_strategy) end private_constant :SequenceMapper, :ParallelMapper end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bcdd-contract-0.1.0 | lib/bcdd/contract/unit/checker.rb |