View Source Sourceror.Code.Tuple (Sourceror v1.11.0)
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
@spec append_elem(Sourceror.Zipper.t(), quoted :: Macro.t()) :: {:ok, Sourceror.Zipper.t()} | :error
Appends quoted to the tuple.
Examples
iex> zipper = Sourceror.parse_string!("{1, 2}") |> Sourceror.Zipper.zip()
iex> {:ok, zipper} = Sourceror.Code.Tuple.append_elem(zipper, 3)
iex> Sourceror.to_string(zipper.node)
"{1, 2, 3}"See also tuple_elem/2.
@spec elem_equals?(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 = Sourceror.parse_string!("{1, 2, 3}") |> Sourceror.Zipper.zip()
iex> Sourceror.Code.Tuple.elem_equals?(zipper, 0, 1)
true
iex> Sourceror.Code.Tuple.elem_equals?(zipper, 0, 2)
falseSee also tuple_elem/2.
@spec tuple?(Sourceror.Zipper.t()) :: boolean()
Returns true if the zipper is at a literal tuple, false if not.
Examples
iex> zipper = Sourceror.parse_string!("{1, 2, 3}") |> Sourceror.Zipper.zip()
iex> Sourceror.Code.Tuple.tuple?(zipper)
true
iex> zipper = Sourceror.parse_string!("[1, 2, 3]") |> Sourceror.Zipper.zip()
iex> Sourceror.Code.Tuple.tuple?(zipper)
falseSee also tuple_elem/2.
@spec tuple_elem(Sourceror.Zipper.t(), elem :: non_neg_integer()) :: {:ok, 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 = Sourceror.parse_string!("{1, 2, 3}") |> Sourceror.Zipper.zip()
iex> {:ok, result} = Sourceror.Code.Tuple.tuple_elem(zipper, 1)
iex> match?({:__block__, _, [2]}, result.node)
trueSee also tuple?/1.