Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

File System Todo

exercises/file_system_todo_app.livemd

File System Todo

Mix.install([
  {:jason, "~> 1.4"},
  {:kino, "~> 0.9", override: true},
  {:youtube, github: "brooklinjazz/youtube"},
  {:hidden_cell, github: "brooklinjazz/hidden_cell"}
])

Navigation

Home Report An Issue Save GameDocument Tools

Overview

You’re going to create a TodoList application with persistence using a file system.

Example Solution

defmodule TodoList do
  @storage "todolist"

  def list do
    case File.read(@storage) do
      {:ok, list} -> :erlang.binary_to_term(list)
      # other operations will create the storage if it does not yet exist.
      _ -> []
    end
  end

  def add(item) do
    new_list = [item | list()]
    File.write(@storage, :erlang.term_to_binary(new_list))
  end

  def complete(item) do
    new_list = list() -- [item]
    File.write(@storage, :erlang.term_to_binary(new_list))
  end
end

Implement the TodoList module as documented. You may choose any file for your persistence mechanism.

defmodule TodoList do
  @moduledoc """
  Documentation for `TodoList`
  """
  @doc """
  Retrieve the todo list.

  ## Examples

      iex> TodoList.list()
      []
  """
  def list do
  end

  @doc """
  Add an item to the todo list.

  ## Examples

      TodoList.add("task 1")
      TodoList.add("task 2")
      TodoList.list()
      ["task 2", "task 1"]
  """
  def add(item) do
  end

  @doc """
  Complete (remove) an item from the todo list.

  ## Examples

      TodoList.add("finish homework")
      TodoList.complete("finish homework")
      TodoList.list()
      ["task 2", "task 1"]
  """
  def complete(item) do
  end
end

Commit Your Progress

DockYard Academy now recommends you use the latest Release rather than forking or cloning our repository.

Run git status to ensure there are no undesirable changes. Then run the following in your command line from the curriculum folder to commit your progress.

$ git add .
$ git commit -m "finish File System Todo exercise"
$ git push

We’re proud to offer our open-source curriculum free of charge for anyone to learn from at their own pace.

We also offer a paid course where you can learn from an instructor alongside a cohort of your peers. We will accept applications for the June-August 2023 cohort soon.

Navigation

Home Report An Issue Save GameDocument Tools