lib/prop_check/generator.rb in prop_check-0.7.1 vs lib/prop_check/generator.rb in prop_check-0.8.0

- old
+ new

@@ -70,11 +70,11 @@ # inner_generator = generator_proc.call(outer_val) # inner_generator.generate(size, rng) # end.flatten # end Generator.new do |size, rng| - outer_result = generate(size, rng) + outer_result = self.generate(size, rng) outer_result.bind do |outer_val| inner_generator = generator_proc.call(outer_val) inner_generator.generate(size, rng) end end @@ -88,8 +88,27 @@ def map(&proc) Generator.new do |size, rng| result = self.generate(size, rng) result.map(&proc) end + end + + ## + # Creates a new Generator that only produces a value when the block `condition` returns a truthy value. + def where(&condition) + self.map do |result| + if condition.call(*result) + result + else + :"_PropCheck.filter_me" + end + end + # self.map do |*result| + # if condition.call(*result) + # result + # else + # :'_PropCheck.filter_me' + # end + # end end end end