# View Source Multitool.Numbers.Primes(multitool v0.2.0)

Provides operations for working with prime numbers

A number is prime if it has only two factors, itself and one

# Link to this section Summary

## Functions

Returns the nth prime number, where the first prime number is two.

Checks if the given number is a prime number.

Generates a Stream of prime numbers, starting at the first prime number, two.

Generates a list of `n` prime numbers, starting at the first prime number, two.

# nth_prime(n)

View Source (since 0.1.0)

Returns the nth prime number, where the first prime number is two.

Returns `nil` when `n` is less than one

## parameters Parameters

``n: The nth prime number to retrieve``

## examples Examples

``````iex> nth_prime(3)
5
iex> nth_prime(-1)
nil
iex> nth_prime(98764)
1282201``````

# prime?(n)

View Source (since 0.1.0)

Checks if the given number is a prime number.

Returns `true` if the number is prime, `false` otherwise. Numbers less than two always return `false`

## parameters Parameters

``n: Integer to check for primality``

## examples Examples

``````iec
iex> prime?(-1)
false

iex> prime?(1)
false

iex> prime?(3)
true

iex> prime?(9800)
false``````

# primes()

View Source (since 1.2.0)

Generates a Stream of prime numbers, starting at the first prime number, two.

This operation will produce prime numbers until a terminating condition is reached

## examples Examples

``````iex> primes() |> Enum.take(0)
[]

iex> primes() |> Enum.take(1)
[2]

iex> primes() |> Enum.take(10)
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]``````

# primes(n)

View Source (since 0.1.0)

Generates a list of `n` prime numbers, starting at the first prime number, two.

An empty list is returned when `n` is less than one

## parameters Parameters

``n: The number of prime numbers to generate``

## examples Examples

``````iex> primes(-1)
[]

iex> primes(1)
[2]

iex> primes(10)
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]``````