Sha256: fa72923ef349bea9a7bc1dc2c72ce0e8da5c2033e330ceef45a3dea7daddbe40

Contents?: true

Size: 749 Bytes

Versions: 4

Compression:

Stored size: 749 Bytes

Contents

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

  def add
    sum
  end

  def even
    remainder_is(2, 0)
  end

  def odd
    remainder_is(2, 1)
  end

  def divide(divisor)
    ->(dividend) { dividend / divisor }
  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(enumerator_of(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

  def greater_than(right)
    ->(left) { left > right }
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
totally_lazy-0.1.26 lib/totally_lazy/numbers.rb
totally_lazy-0.1.25 lib/totally_lazy/numbers.rb
totally_lazy-0.1.24 lib/totally_lazy/numbers.rb
totally_lazy-0.1.23 lib/totally_lazy/numbers.rb