Skip to content

Latest commit

聽

History

History
112 lines (75 loc) 路 1.8 KB

File metadata and controls

112 lines (75 loc) 路 1.8 KB

Elixir Koans - 06 Lists

import ExUnit.Assertions

We can see what is ahead

assert List.first([1, 2, 3]) == ___

Checking what's trailing is also simple

assert List.last([1, 2, 3]) == ___

Lists can store anything you throw at them

assert [1, 2] ++ [:a, "b"] == ___

Things can evolve

assert [1, 2, 3] -- [3] == ___

Evolution can have different forms

assert List.delete([:a, :b, :c], :b) == ___

Precision is also valued

assert List.delete_at([:a, :b, :c], 2) == ___

Replication is also possible

assert List.duplicate("life", 3) == ___

Sometimes leveling the playing field is desired

assert List.flatten([1, [2, 3], 4, [5]]) == ___

Order can also be specified for new members

assert List.insert_at([1, 2, 3], 1, 4) == ___

We can replace things at specified positions

assert List.replace_at([1, 2, 3], 0, 10) == ___

When a replacement cannot be found, the list remains the same

assert List.replace_at([1, 2, 3], 10, 0) == ___

Order is bound by nature's laws

assert List.insert_at([1, 2, 3], 10, 4) == ___

Sometimes it's faster to loop around back

assert List.insert_at([1, 2, 3], -1, 4) == ___

We can also transform ourselves completely

assert List.to_tuple([1, 2, 3]) == ___

Wrapping other values is a handy option

assert List.wrap("value") == ___

Wrapping nothing produces a list of nothing

assert List.wrap(nil) == ___

When there is already a list do not wrap it again

assert List.wrap(["value"]) == ___

Next Steps