Sha256: a8a4bff0d86a93e8711b42b32bf7500a4bd2d14fbac3a82d5d916d05bd9f1c03

Contents?: true

Size: 1.89 KB

Versions: 69

Compression:

Stored size: 1.89 KB

Contents

defmodule BinTree do
  import Inspect.Algebra

  @moduledoc """
  A node in a binary tree.

  `value` is the value of a node.
  `left` is the left subtree (nil if no subtree).
  `right` is the right subtree (nil if no subtree).
  """
  @type t :: %BinTree{value: any, left: BinTree.t() | nil, right: BinTree.t() | nil}
  defstruct value: nil, left: nil, right: nil

  # A custom inspect instance purely for the tests, this makes error messages
  # much more readable.
  #
  # BT[value: 3, left: BT[value: 5, right: BT[value: 6]]] becomes (3:(5::(6::)):)
  def inspect(%BinTree{value: v, left: l, right: r}, opts) do
    concat([
      "(",
      to_doc(v, opts),
      ":",
      if(l, do: to_doc(l, opts), else: ""),
      ":",
      if(r, do: to_doc(r, opts), else: ""),
      ")"
    ])
  end
end

defmodule Zipper do
  @doc """
  Get a zipper focused on the root node.
  """
  @spec from_tree(BT.t()) :: Z.t()
  def from_tree(bt) do
  end

  @doc """
  Get the complete tree from a zipper.
  """
  @spec to_tree(Z.t()) :: BT.t()
  def to_tree(z) do
  end

  @doc """
  Get the value of the focus node.
  """
  @spec value(Z.t()) :: any
  def value(z) do
  end

  @doc """
  Get the left child of the focus node, if any.
  """
  @spec left(Z.t()) :: Z.t() | nil
  def left(z) do
  end

  @doc """
  Get the right child of the focus node, if any.
  """
  @spec right(Z.t()) :: Z.t() | nil
  def right(z) do
  end

  @doc """
  Get the parent of the focus node, if any.
  """
  @spec up(Z.t()) :: Z.t()
  def up(z) do
  end

  @doc """
  Set the value of the focus node.
  """
  @spec set_value(Z.t(), any) :: Z.t()
  def set_value(z, v) do
  end

  @doc """
  Replace the left child tree of the focus node.
  """
  @spec set_left(Z.t(), BT.t()) :: Z.t()
  def set_left(z, l) do
  end

  @doc """
  Replace the right child tree of the focus node.
  """
  @spec set_right(Z.t(), BT.t()) :: Z.t()
  def set_right(z, r) do
  end
end

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/elixir/exercises/zipper/zipper.exs
trackler-2.2.1.179 tracks/elixir/exercises/zipper/zipper.exs
trackler-2.2.1.178 tracks/elixir/exercises/zipper/zipper.exs
trackler-2.2.1.177 tracks/elixir/exercises/zipper/zipper.exs
trackler-2.2.1.176 tracks/elixir/exercises/zipper/zipper.exs
trackler-2.2.1.175 tracks/elixir/exercises/zipper/zipper.exs
trackler-2.2.1.174 tracks/elixir/exercises/zipper/zipper.exs
trackler-2.2.1.173 tracks/elixir/exercises/zipper/zipper.exs
trackler-2.2.1.172 tracks/elixir/exercises/zipper/zipper.exs
trackler-2.2.1.171 tracks/elixir/exercises/zipper/zipper.exs
trackler-2.2.1.170 tracks/elixir/exercises/zipper/zipper.exs
trackler-2.2.1.169 tracks/elixir/exercises/zipper/zipper.exs
trackler-2.2.1.167 tracks/elixir/exercises/zipper/zipper.exs
trackler-2.2.1.166 tracks/elixir/exercises/zipper/zipper.exs
trackler-2.2.1.165 tracks/elixir/exercises/zipper/zipper.exs
trackler-2.2.1.164 tracks/elixir/exercises/zipper/zipper.exs
trackler-2.2.1.163 tracks/elixir/exercises/zipper/zipper.exs
trackler-2.2.1.162 tracks/elixir/exercises/zipper/zipper.exs
trackler-2.2.1.161 tracks/elixir/exercises/zipper/zipper.exs
trackler-2.2.1.160 tracks/elixir/exercises/zipper/zipper.exs