Htam v0.2.1 Math.Enum View Source

Math.Enum defines Math-functions that work on any collection extending the Enumerable protocol. This means Maps, Lists, Sets, etc., and any custom collection types as well.

Link to this section Summary

Functions

Calculates the mean of a collection of numbers.

Calculates the median of a given collection of numbers.

Calculates the product, obtained by multiplying all elements in collection with eachother.

Link to this section Functions

Calculates the mean of a collection of numbers.

This is the sum, divided by the amount of elements in the collection.

If the collection is empty, returns nil

Also see Math.Enum.median/1

Examples

iex> Math.Enum.mean [1,2,3]
2.0
iex> Math.Enum.mean 1..10
5.5
iex> Math.Enum.mean [1,2,3,4,5, -100]
-14.166666666666666
iex> Math.Enum.mean []
nil
Link to this function

median(collection) View Source
median(Enum.t()) :: number() | nil

Calculates the median of a given collection of numbers.

  • If the collection has an odd number of elements, this will be the middle-most element of the (sorted) collection.
  • If the collection has an even number of elements, this will be mean of the middle-most two elements of the (sorted) collection.

If the collection is empty, returns nil

Also see Math.Enum.mean/1

Examples

iex> Math.Enum.median [1,2,3]
2
iex> Math.Enum.median 1..10
5.5
iex> Math.Enum.median [1,2,3,4,5, -100]
2.5
iex> Math.Enum.median [1,2]
1.5
iex> Math.Enum.median []
nil

Calculates the product, obtained by multiplying all elements in collection with eachother.

Examples

iex> Math.Enum.product [1,2,3]
6
iex> Math.Enum.product 1..10
3628800
iex> Math.Enum.product [1,2,3,4,5, -100]
-12000