mathx v0.1.0 Mathx.Enum

Mathx.Enum defines Mathx-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

Link to this function mean(collection)
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 Mathx.Enum.median/1

Examples

iex> Mathx.Enum.mean [1,2,3]
2.0
iex> Mathx.Enum.mean 1..10
5.5
iex> Mathx.Enum.mean [1,2,3,4,5, -100]
-14.166666666666666
iex> Mathx.Enum.mean []
nil
Link to this function median(collection)
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 Mathx.Enum.mean/1

Examples

iex> Mathx.Enum.median [1,2,3]
2
iex> Mathx.Enum.median 1..10
5.5
iex> Mathx.Enum.median [1,2,3,4,5, -100]
2.5
iex> Mathx.Enum.median [1,2]
1.5
iex> Mathx.Enum.median []
nil
Link to this function product(collection)

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

Examples

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