Population v0.1.2 Population

Elixir OTP application library for the World Population API

Public API

Countries: list available countries

Life Expectancy: calculate life expectancy

Mortality Distribution: retrieve mortality distribution tables

World Population Rank: determine world population rank

Population : retrieve population tables

Summary

Functions

Retrieves a list of all countries in the statistical dataset

Retrieves a list of all countries in the statistical dataset

Calculates the day on which a person with the given date of birth, sex and country of origin has reached (or will reach) a certain world population rank

Calculates the day on which a person with the given date of birth, sex and country of origin has reached (or will reach) a certain world population rank

Retrieves the mortality distribution tables for the given country, sex and age

Retrieves the mortality distribution tables for the given country, sex and age

Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by the person’s age

Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by the person’s age

Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date

Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date

Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by an offset towards the future from today

Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by an offset towards the future from today

Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by an offset towards the past from today

Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by an offset towards the past from today

Calculates the world population rank of a person with the given date of birth, sex and country of origin as of today

Calculates the world population rank of a person with the given date of birth, sex and country of origin as of today

Calculates the remaining life expectancy of a person with given sex, country, and age at a given point in time

Calculates the remaining life expectancy of a person with given sex, country, and age at a given point in time

Retrieves the population table for a specific age group in the given year and country

Retrieves the population table for a specific age group in the given year and country

Determines total population for a given country on a given date. Valid dates are 2013-01-01 to 2022-12-31

Determines total population for a given country on a given date. Valid dates are 2013-01-01 to 2022-12-31

Retrieves the population table for all countries and a specific age group in the given year

Retrieves the population table for all countries and a specific age group in the given year

Retrieves the population tables for a given year and country. Returns tables for all ages from 0 to 100

Retrieves the population tables for a given year and country. Returns tables for all ages from 0 to 100

Retrieves the population tables for a specific age group in the given country. Returns tables for all years from 1950 to 2100

Retrieves the population tables for a specific age group in the given country. Returns tables for all years from 1950 to 2100

Determines total population for a given country with separate results for today and tomorrow

Determines total population for a given country with separate results for today and tomorrow

Calculates the total life expectancy of a person with given sex, country, and date of birth

Calculates the total life expectancy of a person with given sex, country, and date of birth

Types

countries()
countries() :: [String.t]
date_by_rank()
date_by_rank() :: %{dob: String.t, sex: rgender, country: String.t, rank: integer, date_on_rank: String.t}
day()
day() :: 0..31
failure()
failure() :: {:error, String.t}
gender()
gender() :: :male | :female
month()
month() :: 0..12
mortality_dist()
mortality_dist() :: [mortality_table]
mortality_table()
mortality_table() :: %{age: integer, mortality_percent: float}
offset()
offset() :: {year, month, day} | {year, month} | {year}
population_contrast()
population_contrast() :: %{today: total_population, tomorrow: total_population}
population_table()
population_table() :: %{total: integer, females: integer, males: integer, year: valid_year, age: valid_age}
population_tables()
population_tables() :: [population_table]
rank_by_age()
rank_by_age() :: %{dob: String.t, sex: rgender, country: String.t, rank: integer, age: String.t}
rank_by_date()
rank_by_date() :: %{dob: String.t, sex: rgender, country: String.t, rank: integer, date: String.t}
rank_today()
rank_today() :: %{dob: String.t, sex: rgender, country: String.t, rank: integer}
rank_with_offset()
rank_with_offset() :: %{dob: String.t, sex: rgender, country: String.t, rank: integer, offset: String.t}
remaining_life()
remaining_life() :: %{sex: gender, country: String.t, date: String.t, remaining_life_expectancy: float}
rgender()
rgender() :: gender | :unisex
total_life()
total_life() :: %{sex: gender, country: String.t, date: String.t, total_life_expectancy: float}
total_population()
total_population() :: %{date: String.t, population: integer}
valid_age()
valid_age() :: 0..100
valid_year()
valid_year() :: 1950..2100
year()
year() :: integer

Functions

countries()
countries() :: {:ok, countries} | failure

Retrieves a list of all countries in the statistical dataset.

Returns {:ok,countries/0} if the call succeed, otherwise {:error, reason}.

Examples

iex> countries
{:ok, ["Afghanistan", "Albania", "Algeria", ...]}
countries!()
countries!() :: countries | no_return

Retrieves a list of all countries in the statistical dataset.

Returns the list of countries/0 if the call succeed, otherwise raises a RuntimeError with a message including the reason.

Examples

iex> countries!
["Afghanistan", "Albania", "Algeria", ...]
date_by_rank(dob, gender, country, rank)
date_by_rank(Date.t, gender, String.t, integer) ::
  {:ok, date_by_rank} |
  failure

Calculates the day on which a person with the given date of birth, sex and country of origin has reached (or will reach) a certain world population rank.

Returns {:ok,date_by_rank/0} if the call succeed, otherwise {:error, reason}.

Examples

iex> date_by_rank(~D[1992-06-21], :unisex, "Colombia", 1_000_000)
{:ok,
 %{country: "Colombia", date_on_rank: "1993-07-29", dob: "1992-06-21",
   rank: 1000000, sex: :unisex}}
iex> date_by_rank(~D[0600-06-21], :unisex, "Colombia", 1_000_000)
{:error,
 "The birthdate 0600-06-21 can not be processed, only dates between 1920-01-01 and 2059-12-31 are supported"}
date_by_rank!(dob, gender, country, rank)
date_by_rank!(Date.t, gender, String.t, integer) ::
  date_by_rank |
  no_return

Calculates the day on which a person with the given date of birth, sex and country of origin has reached (or will reach) a certain world population rank.

Returns date_by_rank/0 if the call succeed, raises a RuntimeError with a message including the reason.

Examples

iex> date_by_rank!(~D[1992-06-21], :unisex, "Colombia", 1_000_000)
%{country: "Colombia", date_on_rank: "1993-07-29", dob: "1992-06-21",
  rank: 1000000, sex: :unisex}
iex> date_by_rank!(~D[0600-06-21], :unisex, "Colombia", 1_000_000)
** (RuntimeError) The birthdate 0600-06-21 can not be processed, only dates between 1920-01-01 and 2059-12-31 are supported
mortality_distribution(country, gender, age)
mortality_distribution(String.t, gender, offset) ::
  {:ok, mortality_dist} |
  failure

Retrieves the mortality distribution tables for the given country, sex and age.

Returns {:ok,mortality_dist/0} if the call succeed, otherwise {:error, reason}.

Examples

iex> mortality_distribution("Colombia", :female, {49, 2})
{:ok,
 [%{age: 45.0, mortality_percent: 0.0},
  %{age: 50.0, mortality_percent: 0.25014423810470543},
  %{age: 55.0, mortality_percent: 2.1978408779738965},
  %{age: 60.0, mortality_percent: 3.0818990812279665},
  ...]}
iex> mortality_distribution("Colombia", :random, {49, 2})
{:error,
 "random is an invalid value for the parameter "sex", valid values are: male, female, unisex"}
mortality_distribution!(country, gender, age)
mortality_distribution!(String.t, gender, offset) ::
  mortality_dist |
  no_return

Retrieves the mortality distribution tables for the given country, sex and age.

Returns mortality_dist/0 if the call succeed, otherwise raises a RuntimeError with a message including the reason.

Examples

iex> mortality_distribution!("Colombia", :female, {49, 2})
[%{age: 45.0, mortality_percent: 0.0},
 %{age: 50.0, mortality_percent: 0.25014423810470543},
 %{age: 55.0, mortality_percent: 2.1978408779738965},
 %{age: 60.0, mortality_percent: 3.0818990812279665},
 ...]
iex> mortality_distribution!("Colombia", :random, {49, 2})
** (RuntimeError) random is an invalid value for the parameter "sex", valid values are: male, female, unisex
rank_by_age(dob, gender, country, age)
rank_by_age(Date.t, gender, String.t, offset) ::
  {:ok, rank_by_age} |
  failure

Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by the person’s age.

Returns {:ok,rank_by_age/0} if the call succeed, otherwise {:error, reason}.

Examples

iex> rank_by_age(~D[1992-06-21], :unisex, "Colombia", {24, 5})
{:ok,
 %{age: "24y5m0d", country: "Colombia", dob: "1992-06-21", rank: 21567777,
   sex: :unisex}}
iex> rank_by_age(~D[1992-06-21], :random, "Colombia", {24, 5})
{:error,
 "random is an invalid value for the parameter "sex", valid values are: male, female, unisex"}
rank_by_age!(dob, gender, country, age)
rank_by_age!(Date.t, gender, String.t, offset) ::
  rank_by_age |
  no_return

Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by the person’s age.

Returns rank_by_age/0 if the call succeed, otherwise raises a RuntimeError with a message including the reason.

Examples

iex> rank_by_age!(~D[1992-06-21], :unisex, "Colombia", {24, 5})
%{age: "24y5m0d", country: "Colombia", dob: "1992-06-21", rank: 21567777,
  sex: :unisex}
iex> rank_by_age!(~D[1992-06-21], :random, "Colombia", {24, 5})
** (RuntimeError) random is an invalid value for the parameter "sex", valid values are: male, female, unisex
rank_by_date(dob, gender, country, date)
rank_by_date(Date.t, gender, String.t, Date.t) ::
  {:ok, rank_by_date} |
  failure

Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date.

Returns {:ok,rank_by_date/0} if the call succeed, otherwise {:error, reason}.

Examples

iex> rank_by_date(~D[1992-06-21], :unisex, "Colombia", ~D[2016-12-10])
{:ok,
 %{country: "Colombia", date: "2016-12-10", dob: "1992-06-21", rank: 21611869,
   sex: :unisex}}
iex> rank_by_date(~D[1992-06-21], :random, "Colombia", ~D[2016-12-10])
{:error,
 "random is an invalid value for the parameter "sex", valid values are: male, female, unisex"}
rank_by_date!(dob, gender, country, date)
rank_by_date!(Date.t, gender, String.t, Date.t) ::
  rank_by_date |
  no_return

Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date.

Returns rank_by_date/0 if the call succeed, otherwise raises a RuntimeError with a message including the reason.

Examples

iex> rank_by_date!(~D[1992-06-21], :unisex, "Colombia", ~D[2016-12-10])
%{country: "Colombia", date: "2016-12-10", dob: "1992-06-21", rank: 21611869,
  sex: :unisex}
iex> rank_by_date!(~D[1992-06-21], :random, "Colombia", ~D[2016-12-10])
** (RuntimeError) random is an invalid value for the parameter "sex", valid values are: male, female, unisex
rank_in_future(dob, gender, country, future_date)
rank_in_future(Date.t, gender, String.t, offset) ::
  {:ok, rank_with_offset} |
  failure

Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by an offset towards the future from today.

Today’s date is always based on the current time in the timezone UTC.

Returns {:ok,rank_with_offset/0} if the call succeed, otherwise {:error, reason}.

Examples

iex> rank_in_future(~D[1992-06-21], :unisex, "Colombia", {2, 6})
{:ok,
 %{country: "Colombia", dob: "1992-06-21", offset: "2y6m0d", rank: 23711438,
   sex: :unisex}}
iex> rank_in_future(~D[1992-06-21], :random, "Colombia", {2, 6})
{:error,
 "random is an invalid value for the parameter "sex", valid values are: male, female, unisex"}
rank_in_future!(dob, gender, country, future_date)
rank_in_future!(Date.t, gender, String.t, offset) ::
  rank_with_offset |
  no_return

Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by an offset towards the future from today.

Today’s date is always based on the current time in the timezone UTC.

Returns rank_with_offset/0 if the call succeed, raises a RuntimeError with a message including the reason.

Examples

iex> rank_in_future!(~D[1992-06-21], :unisex, "Colombia", {2, 6})
%{country: "Colombia", dob: "1992-06-21", offset: "2y6m0d", rank: 23711438,
  sex: :unisex}
iex> rank_in_future!(~D[1992-06-21], :random, "Colombia", {2, 6})
** (RuntimeError) random is an invalid value for the parameter "sex", valid values are: male, female, unisex
rank_in_past(dob, gender, country, ago)
rank_in_past(Date.t, gender, String.t, offset) ::
  {:ok, rank_with_offset} |
  failure

Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by an offset towards the past from today.

Today’s date is always based on the current time in the timezone UTC.

Returns {:ok,rank_with_offset/0} if the call succeed, otherwise {:error, reason}.

Examples

iex> rank_in_past(~D[1992-06-21], :unisex, "Colombia", {2, 6})
{:ok,
 %{country: "Colombia", dob: "1992-06-21", offset: "2y6m0d", rank: 19478549,
   sex: :unisex}}
iex> rank_in_past(~D[1992-06-21], :random, "Colombia", {2, 6})
{:error,
 "random is an invalid value for the parameter "sex", valid values are: male, female, unisex"}
rank_in_past!(dob, gender, country, ago)
rank_in_past!(Date.t, gender, String.t, offset) ::
  rank_with_offset |
  no_return

Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by an offset towards the past from today.

Today’s date is always based on the current time in the timezone UTC.

Returns rank_with_offset/0 if the call succeed, raises a RuntimeError with a message including the reason.

Examples

iex> rank_in_past!(~D[1992-06-21], :unisex, "Colombia", {2, 6})
%{country: "Colombia", dob: "1992-06-21", offset: "2y6m0d", rank: 19478549,
  sex: :unisex}
iex> rank_in_past!(~D[1992-06-21], :random, "Colombia", {2, 6})
** (RuntimeError) random is an invalid value for the parameter "sex", valid values are: male, female, unisex
rank_today(dob, gender, country)
rank_today(Date.t, gender, String.t) ::
  {:ok, rank_today} |
  failure

Calculates the world population rank of a person with the given date of birth, sex and country of origin as of today.

Today’s date is always based on the current time in the timezone UTC.

Returns {:ok,rank_today/0} if the call succeed, otherwise {:error, reason}.

Examples

iex> rank_today(~D[1992-06-21], :unisex, "Colombia")
{:ok, %{country: "Colombia", dob: "1992-06-21", rank: 21614190, sex: :unisex}}
iex> rank_today(~D[1992-06-21], :random, "Colombia")
{:error,
 "random is an invalid value for the parameter "sex", valid values are: male, female, unisex"}
rank_today!(dob, gender, country)
rank_today!(Date.t, gender, String.t) ::
  rank_today |
  no_return

Calculates the world population rank of a person with the given date of birth, sex and country of origin as of today.

Today’s date is always based on the current time in the timezone UTC.

Returns rank_today/0 if the call succeed, otherwise raises a RuntimeError with a message including the reason.

Examples

iex> rank_today!(~D[1992-06-21], :unisex, "Colombia")
%{country: "Colombia", dob: "1992-06-21", rank: 21614190, sex: :unisex}
iex> rank_today!(~D[1992-06-21], :random, "Colombia")
** (RuntimeError) random is an invalid value for the parameter "sex", valid values are: male, female, unisex
remaining_life_expectancy(gender, country, date, age)
remaining_life_expectancy(gender, String.t, Date.t, offset) ::
  {:ok, remaining_life} |
  failure

Calculates the remaining life expectancy of a person with given sex, country, and age at a given point in time.

Returns {:ok,remaining_life/0} if the call succeed, otherwise {:error, reason}.

Examples

iex> remaining_life_expectancy(:male, "Colombia", ~D[2016-12-10], {24, 5})
{:ok,
 %{age: "24y5m0d", country: "Colombia", date: "2016-12-10",
   remaining_life_expectancy: 54.63260155466486, sex: :male}}
iex> remaining_life_expectancy(:random, "Colombia", ~D[2016-12-10], {24, 5})
{:error, "random is an invalid value for the parameter "sex", valid values are: male, female, unisex"}
remaining_life_expectancy!(gender, country, date, age)
remaining_life_expectancy!(gender, String.t, Date.t, offset) ::
  remaining_life |
  no_return

Calculates the remaining life expectancy of a person with given sex, country, and age at a given point in time.

Returns remaining_life/0 if the call succeed, otherwise raises a RuntimeError with a message including the reason.

Examples

iex> remaining_life_expectancy!(:male, "Colombia", ~D[2016-12-10], {24, 5})
%{age: "24y5m0d", country: "Colombia", date: "2016-12-10",
  remaining_life_expectancy: 54.63260155466486, sex: :male}
iex> remaining_life_expectancy!(:random, "Colombia", ~D[2016-12-10], {24, 5})
** (RuntimeError) random is an invalid value for the parameter "sex", valid values are: male, female, unisex
table_by_country(country, year, age)
table_by_country(String.t, valid_year, valid_age) ::
  {:ok, population_table} |
  failure

Retrieves the population table for a specific age group in the given year and country.

Returns {:ok,population_table/0} if the call succeed, otherwise {:error, reason}.

Examples

iex> table_by_country("Colombia", 2014, 18)
{:ok,
 %{age: 18, country: "Colombia", females: 430971, males: 445096, total: 876067,
   year: 2014}}
iex> table_by_country("Colombia", 2500, 18)
{:error,
 "The year 2500 can not be processed, because only years between 1950 and 2100 are supported"}
table_by_country!(country, year, age)
table_by_country!(String.t, valid_year, valid_age) ::
  population_table |
  no_return

Retrieves the population table for a specific age group in the given year and country.

Returns population_table/0 if the call succeed, otherwise raises a RuntimeError with a message including the reason.

Examples

iex> table_by_country!("Colombia", 2014, 18)
%{age: 18, country: "Colombia", females: 430971, males: 445096, total: 876067,
  year: 2014}
iex> table_by_country!("Colombia", 2500, 18)
** (RuntimeError) The year 2500 can not be processed, because only years between 1950 and 2100 are supported
table_for_country_by_date(country, date)
table_for_country_by_date(String.t, Date.t) ::
  {:ok, population_table} |
  failure

Determines total population for a given country on a given date. Valid dates are 2013-01-01 to 2022-12-31.

Returns {:ok,total_population/0} if the call succeed, otherwise {:error, reason}.

Examples

iex> table_for_country_by_date("Colombia", ~D[2016-12-10])
{:ok, %{date: "2016-12-10", population: 50377885}}
iex> table_for_country_by_date("Colombia", ~D[2012-12-10])
{:error,
 "The calculation date 2012-12-10 can not be processed, only dates between 2013-01-01 and 2022-12-31 are supported"}
table_for_country_by_date!(country, date)
table_for_country_by_date!(String.t, Date.t) ::
  population_table |
  no_return

Determines total population for a given country on a given date. Valid dates are 2013-01-01 to 2022-12-31.

Returns total_population/0 if the call succeed, otherwise raises a RuntimeError with a message including the reason.

Examples

iex> table_for_country_by_date!("Colombia", ~D[2016-12-10])
%{date: "2016-12-10", population: 50377885}
iex> table_for_country_by_date!("Colombia", ~D[2012-12-10])
** (RuntimeError) The calculation date 2012-12-10 can not be processed, only dates between 2013-01-01 and 2022-12-31 are supported
tables(year, age)

Retrieves the population table for all countries and a specific age group in the given year.

Returns {:ok,population_tables/0} if the call succeed, otherwise {:error, reason}.

Examples

iex> tables(2014, 18)
{:ok,
 [%{age: 18, country: "Afghanistan", females: 350820, males: 366763,
    total: 717583, year: 2014},
  %{age: 18, country: "Albania", females: 29633, males: 30478, total: 60111,
    year: 2014},
  ...]}
iex> tables(2500, 18)
{:error,
 "The year 2500 can not be processed, because only years between 1950 and 2100 are supported"}
tables!(year, age)
tables!(valid_year, valid_age) ::
  population_tables |
  no_return

Retrieves the population table for all countries and a specific age group in the given year.

Returns population_tables/0 if the call succeed, otherwise raises a RuntimeError with a message including the reason.

Examples

iex> tables!(2014, 18)
[%{age: 18, country: "Afghanistan", females: 350820, males: 366763,
   total: 717583, year: 2014},
 %{age: 18, country: "Albania", females: 29633, males: 30478, total: 60111,
   year: 2014},
 ...]
iex> tables!(2500, 18)
** (RuntimeError) The year 2500 can not be processed, because only years between 1950 and 2100 are supported
tables_for_all_ages_by_country(country, year)
tables_for_all_ages_by_country(String.t, valid_year) ::
  {:ok, population_tables} |
  failure

Retrieves the population tables for a given year and country. Returns tables for all ages from 0 to 100.

Returns {:ok,population_tables/0} if the call succeed, otherwise {:error, reason}.

Examples

iex> tables_for_all_ages_by_country("Colombia", 2014)
{:ok,
 [%{age: 0, country: "Colombia", females: 432462, males: 452137, total: 884599,
    year: 2014},
  %{age: 1, country: "Colombia", females: 436180, males: 455621, total: 891802,
    year: 2014},
  ...]}
iex> tables_for_all_ages_by_country("Colombia", 2500)
{:error,
 "The year 2500 can not be processed, because only years between 1950 and 2100 are supported"}
tables_for_all_ages_by_country!(country, year)
tables_for_all_ages_by_country!(String.t, valid_year) ::
  population_tables |
  no_return

Retrieves the population tables for a given year and country. Returns tables for all ages from 0 to 100.

Returns population_tables/0 if the call succeed, otherwise raises a RuntimeError with a message including the reason.

Examples

iex> tables_for_all_ages_by_country!("Colombia", 2014)
[%{age: 0, country: "Colombia", females: 432462, males: 452137, total: 884599,
   year: 2014},
 %{age: 1, country: "Colombia", females: 436180, males: 455621, total: 891802,
   year: 2014},
 ...]
iex> tables_for_all_ages_by_country!("Colombia", 2500)
** (RuntimeError) The year 2500 can not be processed, because only years between 1950 and 2100 are supported
tables_for_all_years_by_country(country, age)
tables_for_all_years_by_country(String.t, valid_age) ::
  {:ok, population_tables} |
  failure

Retrieves the population tables for a specific age group in the given country. Returns tables for all years from 1950 to 2100.

Returns {:ok,population_tables/0} if the call succeed, otherwise {:error, reason}.

Examples

iex> tables_for_all_years_by_country("Colombia", 18)
{:ok,
 [%{age: 18, country: "Colombia", females: 114873, males: 116249, total: 231122,
    year: 1950},
  %{age: 18, country: "Colombia", females: 116899, males: 118123, total: 235022,
    year: 1951},
  ...]}
iex> tables_for_all_years_by_country("Colombia", 101)
{:error,
 "The age 101 can not be processed, because only ages between 0 and 100 years are supported"}
tables_for_all_years_by_country!(country, age)
tables_for_all_years_by_country!(String.t, valid_age) ::
  population_tables |
  no_return

Retrieves the population tables for a specific age group in the given country. Returns tables for all years from 1950 to 2100.

Returns population_tables/0 if the call succeed, otherwise raises a RuntimeError with a message including the reason.

Examples

iex> tables_for_all_years_by_country!("Colombia", 18)
[%{age: 18, country: "Colombia", females: 114873, males: 116249, total: 231122,
   year: 1950},
 %{age: 18, country: "Colombia", females: 116899, males: 118123, total: 235022,
   year: 1951},
 ...]
iex> tables_for_all_years_by_country!("Colombia", 101)
** (RuntimeError) The age 101 can not be processed, because only ages between 0 and 100 years are supported
tables_for_today_and_tomorrow_by_country(country)
tables_for_today_and_tomorrow_by_country(String.t) ::
  {:ok, population_contrast} |
  failure

Determines total population for a given country with separate results for today and tomorrow.

Returns {:ok,population_contrast/0} if the call succeed, otherwise {:error, reason}.

Examples

iex> tables_for_today_and_tomorrow_by_country("Colombia")
{:ok,
 %{today: %{date: "2016-12-11", population: 50379477},
   tomorrow: %{date: "2016-12-12", population: 50381070}}}
iex> tables_for_today_and_tomorrow_by_country("Pluton")
{:error,
 "Pluton is an invalid value for the parameter "country", the list of valid values can be retrieved from the endpoint /countries"}
tables_for_today_and_tomorrow_by_country!(country)
tables_for_today_and_tomorrow_by_country!(String.t) ::
  population_contrast |
  no_return

Determines total population for a given country with separate results for today and tomorrow.

Returns population_contrast/0 if the call succeed, otherwise raises a RuntimeError with a message including the reason.

Examples

iex> tables_for_today_and_tomorrow_by_country!("Colombia")
%{today: %{date: "2016-12-11", population: 50379477},
  tomorrow: %{date: "2016-12-12", population: 50381070}}
iex> tables_for_today_and_tomorrow_by_country!("Pluton")
** (RuntimeError) Pluton is an invalid value for the parameter "country", the list of valid values can be retrieved from the endpoint /countries
total_life_expectancy(gender, country, dob)
total_life_expectancy(gender, String.t, Date.t) ::
  {:ok, total_life} |
  failure

Calculates the total life expectancy of a person with given sex, country, and date of birth.

Returns {:ok,total_life/0} if the call succeed, otherwise {:error, reason}.

Examples

iex> total_life_expectancy(:male, "Colombia", ~D[1992-06-21])
{:ok,
 %{country: "Colombia", dob: "1992-06-21", sex: :male,
   total_life_expectancy: 80.89666673632185}}
iex> total_life_expectancy(:random, "Colombia", ~D[1992-06-21])
{:error,
 "random is an invalid value for the parameter "sex", valid values are: male, female, unisex"}
total_life_expectancy!(gender, country, dob)
total_life_expectancy!(gender, String.t, Date.t) ::
  total_life |
  no_return

Calculates the total life expectancy of a person with given sex, country, and date of birth.

Returns total_life/0 if the call succeed, otherwise raises a RuntimeError with a message including the reason.

Examples

iex> total_life_expectancy!(:male, "Colombia", ~D[1992-06-21])
%{country: "Colombia", dob: "1992-06-21", sex: :male,
  total_life_expectancy: 80.89666673632185}
iex> total_life_expectancy!(:male, "Westeros", ~D[1992-06-21])
** (RuntimeError) Westeros is an invalid value for the parameter
"country", the list of valid values can be retrieved from the endpoint /countries