Sha256: 162c01f098f1e5b38b7778c82223f27e2c73eca0ed09d569bf4ce4f5fb873051
Contents?: true
Size: 767 Bytes
Versions: 8
Compression:
Stored size: 767 Bytes
Contents
module PropCheck ## # Helper functions that have no other place to live module Helper extend self ## # Creates a (potentially lazy) Enumerator # starting with `elem` # with each consecutive element obtained # by calling `operation` on the previous element. # # >> Helper.scanl(0, &:next).take(10).force # => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] # >> Helper.scanl([0, 1]) { |curr, next_elem| [next_elem, curr + next_elem] }.map(&:first).take(10).force # => [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] def scanl(elem, &operation) Enumerator.new do |yielder| acc = elem loop do # p acc yielder << acc acc = operation.call(acc) end end.lazy end end end
Version data entries
8 entries across 8 versions & 1 rubygems