Sha256: 29353844fdd6de0bbdc2aac029e886ebebff25ed83bef1dcc711c19988be1a63

Contents?: true

Size: 655 Bytes

Versions: 1

Compression:

Stored size: 655 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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
totally_lazy-0.1.14 lib/numbers.rb