Map Sorter v0.1.16 MapSorter.Impl View Source
Generates a sort function from a list of sort specs
(ascending/descending keys).
Link to this section Summary
Functions
Adapts string
to maybe
invoke the comparable/1
function
Converts a value
to a comparable format, if needed
Returns a sort function based on the given sort specs
Returns the AST of a sort function based on the given sort specs
(compile time or runtime)
Link to this section Types
Link to this section Functions
Adapts string
to maybe
invoke the comparable/1
function.
Examples
iex> alias MapSorter.Impl
iex> doc =
...> """
...> &1[:dob] < ...
...> &2[:likes] -> ...
...> """
iex> Impl.adapt_string(doc, true)
"""
Elixir.MapSorter.Impl.comparable(&1[:dob]) < ...
Elixir.MapSorter.Impl.comparable(&2[:likes]) -> ...
"""
iex> alias MapSorter.Impl
iex> doc =
...> """
...> &1[:dob] < ...
...> &2[:likes] -> ...
...> """
iex> Impl.adapt_string(doc, false)
"""
&1[:dob] < ...
&2[:likes] -> ...
"""
Converts a value
to a comparable format, if needed.
Examples
iex> alias MapSorter.Impl
iex> Impl.comparable(~T[15:41:33])
"15:41:33"
iex> alias MapSorter.Impl
iex> Impl.comparable(3.1416)
3.1416
Returns a sort function based on the given sort specs
.
Examples
iex> alias MapSorter.Impl
iex> Logger.configure(level: :info) # :debug → debug messages
iex> sort_fun = Impl.eval_sort_fun([:dob, desc: :likes])
iex> Logger.configure(level: :info)
iex> is_function(sort_fun, 2)
true
Link to this function
sort_fun(sort_specs)
View Source
sort_fun([sort_spec()] | Macro.expr()) :: Macro.expr()
Returns the AST of a sort function based on the given sort specs
(compile time or runtime).
Examples
iex> alias MapSorter.Impl
iex> sort_specs = [:dob, desc: :likes]
iex> Logger.configure(level: :info) # :debug → debug messages
iex> sort_fun = Impl.sort_fun(sort_specs)
iex> Logger.configure(level: :info)
iex> match?({:&, _meta, _args}, sort_fun) and
iex> match?([_, _], sort_specs)
true
iex> alias MapSorter.Impl
iex> sort_specs = quote do: Tuple.to_list({:dob, {:desc, :likes}})
iex> Logger.configure(level: :info) # :debug → debug messages
iex> sort_fun = Impl.sort_fun(sort_specs)
iex> Logger.configure(level: :info)
iex> match?({{:., _, _}, _meta, _args}, sort_fun) and
iex> match?({{:., _, _}, _meta, _args}, sort_specs)
true