math v0.2.0 Math.Enum
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.
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
Functions
Specs
mean(Enum.t) :: number
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
Specs
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
6.5
iex> Math.Enum.median [1,2,3,4,5, -100]
3.5
iex> Math.Enum.median []
nil