primex v0.1.0 Primex View Source

This is an educational exercise in refactoring someone else's code. The original source comes from http://rosettacode.org/wiki/Sieve_of_Eratosthenes#Elixir

Link to this section Summary

Types

t:cis is a user-defined type, which is a tuple of an integer and a function that resolves to another t:cis

t:ciss is a user-defined type, which is a tuple of a t:cis (above) and a function that resolves to another t:ciss

Functions

Get a Primes sieve stream

Get a stream of Primes under the given limit

Link to this section Types

Link to this type

cis()

View Source
cis() :: {integer(), (() -> cis())}

t:cis is a user-defined type, which is a tuple of an integer and a function that resolves to another t:cis

Link to this type

ciss()

View Source
ciss() :: {cis(), (() -> ciss())}

t:ciss is a user-defined type, which is a tuple of a t:cis (above) and a function that resolves to another t:ciss

Link to this section Functions

Get a Primes sieve stream

Examples

iex> Primex.stream() |> Stream.take(25) |> Enum.to_list()
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

iex> Primex.stream() |> Stream.take_while(&(&1 < 100)) |> Enum.to_list()
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

Get a stream of Primes under the given limit

Examples

iex> Primex.under(100) |> Enum.to_list()
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]