Sha256: 69e5b9ef1c43af6ea4f28d71682fca8e4fc409ea38d9e391ee3492c11e06cda0

Contents?: true

Size: 791 Bytes

Versions: 25

Compression:

Stored size: 791 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)
    ->(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

25 entries across 25 versions & 1 rubygems

Version Path
totally_lazy-0.1.53 lib/totally_lazy/numbers.rb
totally_lazy-0.1.52 lib/totally_lazy/numbers.rb
totally_lazy-0.1.51 lib/totally_lazy/numbers.rb
totally_lazy-0.1.50 lib/totally_lazy/numbers.rb
totally_lazy-0.1.49 lib/totally_lazy/numbers.rb
totally_lazy-0.1.48 lib/totally_lazy/numbers.rb
totally_lazy-0.1.47 lib/totally_lazy/numbers.rb
totally_lazy-0.1.46 lib/totally_lazy/numbers.rb
totally_lazy-0.1.45 lib/totally_lazy/numbers.rb
totally_lazy-0.1.44 lib/totally_lazy/numbers.rb
totally_lazy-0.1.43 lib/totally_lazy/numbers.rb
totally_lazy-0.1.42 lib/totally_lazy/numbers.rb
totally_lazy-0.1.41 lib/totally_lazy/numbers.rb
totally_lazy-0.1.39 lib/totally_lazy/numbers.rb
totally_lazy-0.1.38 lib/totally_lazy/numbers.rb
totally_lazy-0.1.37 lib/totally_lazy/numbers.rb
totally_lazy-0.1.36 lib/totally_lazy/numbers.rb
totally_lazy-0.1.35 lib/totally_lazy/numbers.rb
totally_lazy-0.1.34 lib/totally_lazy/numbers.rb
totally_lazy-0.1.33 lib/totally_lazy/numbers.rb