Sha256: 7597ce312613c84cb375705ca6421cf4ae64d3cb19b2a767c5f9b7f579dd477f
Contents?: true
Size: 752 Bytes
Versions: 4
Compression:
Stored size: 752 Bytes
Contents
module Dry module Validation def self.Predicate(block) case block when Method then Predicate.new(block.name, &block) else raise ArgumentError, 'predicate needs an :id' end end class Predicate include Dry::Equalizer(:id) attr_reader :id, :args, :fn def initialize(id, *args, &block) @id = id @fn = block @args = args end def call(*args) fn.(*args) end def negation self.class.new(:"not_#{id}") { |input| !fn.(input) } end def curry(*args) self.class.new(id, *args, &fn.curry.(*args)) end def to_ary [:predicate, [id, args]] end alias_method :to_a, :to_ary end end end
Version data entries
4 entries across 4 versions & 1 rubygems