Sha256: aa7a4f12f13d11fe2bf61ed1e5d0680ddfc83eec66ca2c4ed1b02dedea2408f2

Contents?: true

Size: 592 Bytes

Versions: 2

Compression:

Stored size: 592 Bytes

Contents

module Numbers
  def sum
    monoid(->(a, b) { a + b }, 0)
  end

  def even
    remainder_is(2, 0)
  end

  def odd
    remainder_is(2, 1)
  end

  def remainder_is(divisor, remainder)
    ->(dividend) { remainder(dividend, divisor) == remainder }
  end

  def remainder(dividend, divisor)
    dividend % divisor
  end

  def range_from(start)
    Sequence.new(Enumerators::enumerator(increment, start))
  end

  def range(from, to)
    Sequence.new((from..to).lazy)
  end

  def increment
    ->(number) { number + 1 }
  end

  def mod(divisor)
    ->(number) { number % divisor }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
totally_lazy-0.1.13 lib/numbers.rb
totally_lazy-0.1.12 lib/numbers.rb