Sha256: 4ba1ea3584142bc2eedc634f44cbb0bfe5f61adaab92b1124cecc3f6dbe34562

Contents?: true

Size: 654 Bytes

Versions: 1

Compression:

Stored size: 654 Bytes

Contents

# frozen_string_literal: true

# Extend the core Kernel module
module Kernel
  # Version of the notation library
  NOTATION_VERSION = '0.2.2'

  # Make lambda a true lambda
  #
  # Example:
  #   λ { puts 'Hello' }.call => 'Hello'
  #
  alias λ proc

  # Sigma, i.e. the sum of all elements.
  #
  # Example:
  #   ∑ [1,2,3] => 6
  #
  def ∑(*args)
    args.inject(0){ |e, m| m + e }
  end

  # Pi product, i.e. the product of all elements.
  #
  # Example:
  #   ∏ [2,3,4] => 24
  #
  def ∏(*args)
    args.inject(1){ |e, m| m * e }
  end

  # Square root
  #
  # Example:
  #   √ 49 => 7.0
  #
  def √(root)
    Math.sqrt(root)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
notation-0.2.2 lib/notation.rb