animals_sample v0.1.0 Animals

Documentation for Animals.

Link to this section Summary

Functions

contains? takes a list of zoo animals and a single animal and returns a boolean as to whether or not the list contains the given animal.

create_zoo returns a list of zoo animals

load takes filename and returns a list of animals if the file exists

randomise takes a list of zoo animals and returns a new randomised list with the same elements as the first.

save takes a list of zoo animals and a filename and saves the list to that file

see_animals takes a list of zoo animals and the number of animals that you want to see and then returns a list

selection takes a number, creates a zoo, randomises it and then returns a list of animals of length selected

Link to this section Functions

Link to this function

contains?(zoo, animal)

contains? takes a list of zoo animals and a single animal and returns a boolean as to whether or not the list contains the given animal.

Examples

iex> zoo = Animals.create_zoo
iex> Animals.contains?(zoo, "gorilla")
true

create_zoo returns a list of zoo animals

Examples

iex> Animals.create_zoo
["lion", "tiger", "gorilla", "elephant", "monkey", "giraffe"]

load takes filename and returns a list of animals if the file exists

Examples

iex> Animals.load("my_animals")
["lion", "tiger", "gorilla", "elephant", "monkey", "giraffe"]
iex> Animals.load("aglkjhdfg")
"File does not exist"

randomise takes a list of zoo animals and returns a new randomised list with the same elements as the first.

Examples

iex> :rand.seed(:exsplus, {1, 2, 3})
iex> zoo = Animals.create_zoo
iex> Animals.randomise(zoo)
["monkey", "giraffe", "tiger", "lion", "elephant", "gorilla"]
Link to this function

save(zoo, filename)

save takes a list of zoo animals and a filename and saves the list to that file

Examples

iex> zoo = Animals.create_zoo
iex> Animals.save(zoo, "my_animals")
:ok
Link to this function

see_animals(zoo, count)

see_animals takes a list of zoo animals and the number of animals that you want to see and then returns a list

Examples

iex> zoo = Animals.create_zoo
iex> Animals.see_animals(zoo, 2)
["monkey", "giraffe"]
Link to this function

selection(number_of_animals)

selection takes a number, creates a zoo, randomises it and then returns a list of animals of length selected

Examples

iex> :rand.seed(:exsplus, {1, 2, 3})
iex> Animals.selection(2)
["elephant", "gorilla"]