Capstone.Vendor.Sourceror.Code.Tuple (Capstone v0.33.3)

Copy Markdown View Source

Utilities for working with tuples.

Summary

Functions

Appends quoted to the tuple.

Returns true if the element at the given index equals the given value.

Returns true if the zipper is at a literal tuple, false if not.

Returns a zipper at the tuple element at the given index, or :error if the index is out of bounds.

Functions

append_elem(zipper, quoted)

@spec append_elem(Capstone.Vendor.Sourceror.Zipper.t(), quoted :: Macro.t()) ::
  {:ok, Capstone.Vendor.Sourceror.Zipper.t()} | :error

Appends quoted to the tuple.

Examples

iex> zipper = Capstone.Vendor.Sourceror.parse_string!("{1, 2}") |> Capstone.Vendor.Sourceror.Zipper.zip()
iex> {:ok, zipper} = Capstone.Vendor.Sourceror.Code.Tuple.append_elem(zipper, 3)
iex> Capstone.Vendor.Sourceror.to_string(zipper.node)
"{1, 2, 3}"

See also tuple_elem/2.

elem_equals?(zipper, elem, value)

@spec elem_equals?(
  Capstone.Vendor.Sourceror.Zipper.t(),
  elem :: non_neg_integer(),
  value :: term()
) ::
  boolean()

Returns true if the element at the given index equals the given value.

Examples

iex> zipper = Capstone.Vendor.Sourceror.parse_string!("{1, 2, 3}") |> Capstone.Vendor.Sourceror.Zipper.zip()
iex> Capstone.Vendor.Sourceror.Code.Tuple.elem_equals?(zipper, 0, 1)
true
iex> Capstone.Vendor.Sourceror.Code.Tuple.elem_equals?(zipper, 0, 2)
false

See also tuple_elem/2.

tuple?(item)

Returns true if the zipper is at a literal tuple, false if not.

Examples

iex> zipper = Capstone.Vendor.Sourceror.parse_string!("{1, 2, 3}") |> Capstone.Vendor.Sourceror.Zipper.zip()
iex> Capstone.Vendor.Sourceror.Code.Tuple.tuple?(zipper)
true
iex> zipper = Capstone.Vendor.Sourceror.parse_string!("[1, 2, 3]") |> Capstone.Vendor.Sourceror.Zipper.zip()
iex> Capstone.Vendor.Sourceror.Code.Tuple.tuple?(zipper)
false

See also tuple_elem/2.

tuple_elem(item, elem)

@spec tuple_elem(Capstone.Vendor.Sourceror.Zipper.t(), elem :: non_neg_integer()) ::
  {:ok, Capstone.Vendor.Sourceror.Zipper.t()} | :error

Returns a zipper at the tuple element at the given index, or :error if the index is out of bounds.

Examples

iex> zipper = Capstone.Vendor.Sourceror.parse_string!("{1, 2, 3}") |> Capstone.Vendor.Sourceror.Zipper.zip()
iex> {:ok, result} = Capstone.Vendor.Sourceror.Code.Tuple.tuple_elem(zipper, 1)
iex> match?({:__block__, _, [2]}, result.node)
true

See also tuple?/1.