@@ -1914,20 +1914,19 @@ defmodule Kernel.SpecialForms do
19141914
19151915 ## Examples
19161916
1917- iex> file = "no_file.txt"
1918- iex> case File.read(file) do
1919- ...> {:ok, contents} when is_binary(contents) ->
1920- ...> String.split(contents, "\n")
1921- ...> {:error, _reason} ->
1922- ...> "Can't read the #{file} file"
1917+ iex> string_date = "2015-01-23"
1918+ iex> case Date.from_iso8601(string_date) do
1919+ ...> {:ok, date} -> date
1920+ ...> {:error, _reason} -> Date.utc_today()
19231921 ...> end
1924- "Can't read the no_file.txt file"
1922+ ~D[2015-01-23]
19251923
1926- In the example above, we match the result of `File.read /1`
1924+ In the example above, we match the result of `Date.from_iso8601 /1`
19271925 against each clause "head" and execute the clause "body"
19281926 corresponding to the first clause that matches. In our case
1929- there is no file, so `File.read/1` returns `{:error, :enoent}`
1930- and the second clause is matched.
1927+ `string_date` contains a string with a valid ISO 8601 representation
1928+ of date. The function returns `{:ok, ~D[2015-01-23]}`, so the
1929+ `{:ok, date}` clause is matched.
19311930
19321931 If no clause matches, an error is raised. For this reason,
19331932 it may be necessary to add a final catch-all clause (like `_`)
0 commit comments