A (Aja v0.3.3) View Source
Convenience macros to work with Aja's data structures.
Use import A to import everything, or import only the macros you need.
Link to this section Summary
Link to this section Functions
Convenience macro to work with A.ExRanges (exclusive ranges).
Use import A to use it, or import A, only: [~>: 2].
Examples
iex> 1 ~> 5
1 ~> 5
iex> start ~> stop = 0 ~> 10
iex> {start, stop}
{0, 10}
iex> for i <- 0 ~> 5, do: "id_#{i}"
["id_0", "id_1", "id_2", "id_3", "id_4"]
Convenience macro to create or pattern match on A.OrdMaps.
Use import A to use it, or import A, only: [ord: 1].
Creation examples
iex> ord(%{"一" => 1, "二" => 2, "三" => 3})
#A<ord(%{"一" => 1, "二" => 2, "三" => 3})>
iex> ord(%{a: "Ant", b: "Bat", c: "Cat"})
#A<ord(%{a: "Ant", b: "Bat", c: "Cat"})>Pattern matching examples
iex> ord(%{b: bat}) = ord(%{a: "Ant", b: "Bat", c: "Cat"})
#A<ord(%{a: "Ant", b: "Bat", c: "Cat"})>
iex> bat
"Bat"Replace existing keys examples
iex> ordered = ord(%{a: "Ant", b: "Bat", c: "Cat"})
iex> ord(%{ordered | b: "Buffalo"})
#A<ord(%{a: "Ant", b: "Buffalo", c: "Cat"})>
iex> ord(%{ordered | z: "Zebra"})
** (KeyError) key :z not found in: #A<ord(%{a: "Ant", b: "Bat", c: "Cat"})>
A sigil to build IO data and avoid string concatenation.
Use import A to use it, or import A, only: [sigil_i: 2].
Examples
iex> ~i"atom: #{:foo}, charlist: #{'abc'}, number: #{12 + 2.35}\n"
["atom: ", "foo", ", charlist: ", 'abc', ", number: ", "14.35", 10]
iex> ~i"abc#{['def' | "ghi"]}"
["abc", ['def' | "ghi"]]
iex> ~i"Giorno Giovanna"
"Giorno Giovanna"String interpolation uses A.IO.to_iodata/1 instead of to_string/1, which will preserve lists.
IO-data can be used as is, without any concatenation, by most I/O operations:
- anything from the
IOmodule (writing to a file/stdout...) - anything using a socket
- Phoenix templates
To see the equivalent string, you can use IO.iodata_to_binary/1:
iex> IO.iodata_to_binary ~i"1 + 2 = #{1 + 2}\n"
"1 + 2 = 3\n"
iex> IO.iodata_to_binary ~i"abc#{['def' | "ghi"]}"
"abcdefghi"