Packages

BeamLabCountries is a collection of all sorts of useful information for every country in the [ISO 3166](https://wikipedia.org/wiki/ISO_3166) standard. It includes country data, subdivisions (states/provinces), international organizations, language information, and country name translations.

Current section

Files

Jump to
beamlab_countries lib random.ex
Raw

lib/random.ex

defmodule BeamLabCountries.Random do
@moduledoc """
Module for returning random countries.
"""
@doc """
Returns a random country.
## Examples
iex> %BeamLabCountries.Country{} = BeamLabCountries.Random.country()
"""
@spec country() :: BeamLabCountries.Country.t()
def country do
BeamLabCountries.all() |> Enum.random()
end
@doc """
Returns a random country flag emoji.
## Examples
flag = BeamLabCountries.Random.flag()
String.valid?(flag)
#=> true
"""
@spec flag() :: String.t()
def flag do
BeamLabCountries.all()
|> Enum.filter(&(not is_nil(&1.flag)))
|> Enum.random()
|> Map.get(:flag)
end
end