Sha256: 95a5360cde5db87e6130cee5330725866974b7eae70501560c27246e1997c275

Contents?: true

Size: 932 Bytes

Versions: 4

Compression:

Stored size: 932 Bytes

Contents

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

  def add(increment)
    -> (number) { number + increment }
  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)
    predicate(->(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)
    predicate(->(left) { left > right })
  end

  def multiply(y)
    monoid(->(x){x * y}, 1)
  end

  def powers_of(amount)
    enumerate(multiply(amount), 1)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
totally_lazy-0.1.62 lib/totally_lazy/numbers.rb
totally_lazy-0.1.61 lib/totally_lazy/numbers.rb
totally_lazy-0.1.60 lib/totally_lazy/numbers.rb
totally_lazy-0.1.59 lib/totally_lazy/numbers.rb