Gel.NamedTuple (Gel v0.9.0)
View SourceAn immutable value representing an Gel named tuple value.
Gel.NamedTuple implements Access behavior to access fields
by index or key and Enumerable protocol for iterating over tuple values.
iex(1)> {:ok, client} = Gel.start_link()
iex(2)> nt = Gel.query_required_single!(client, "select (a := 1, b := 'a', c := [3])")
#Gel.NamedTuple<a: 1, b: "a", c: [3]>
iex(3)> nt[:b]
"a"
iex(4)> nt["c"]
[3]
iex(4)> nt[0]
1
Summary
Functions
Get named tuple keys.
Convert a named tuple into a regular map.
Convert a named tuple to a regular erlang tuple.
Types
Functions
Get named tuple keys.
iex(1)> {:ok, client} = Gel.start_link()
iex(2)> nt = Gel.query_required_single!(client, "select (a := 1, b := 'a', c := [3])")
iex(3)> Gel.NamedTuple.keys(nt)
["a", "b", "c"]
Convert a named tuple into a regular map.
iex(1)> {:ok, client} = Gel.start_link()
iex(2)> nt = Gel.query_required_single!(client, "select (a := 1, b := 'a', c := [3])")
iex(3)> Gel.NamedTuple.to_map(nt)
%{"a" => 1, "b" => "a", "c" => [3]}
Convert a named tuple to a regular erlang tuple.
iex(1)> {:ok, client} = Gel.start_link()
iex(2)> nt = Gel.query_required_single!(client, "select (a := 1, b := 'a', c := [3])")
iex(3)> Gel.NamedTuple.to_tuple(nt)
{1, "a", [3]}