Map Sorter v0.1.14 MapSorter.Support View Source
Generates a sort function from a list of sort specs
(ascending/descending keys).
Link to this section Summary
Functions
Adapts the given string
to invoke the sortable/1
function
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)
Converts a value to a sortable format, if needed
Link to this section Types
Link to this section Functions
Adapts the given string
to invoke the sortable/1
function.
Examples
iex> alias MapSorter.Support
iex> Support.adapt(
...> """
...> &1[:dob] < ...
...> &2[:likes] -> ...
...> """
...> )
"""
MapSorter.Support.sortable(&1[:dob]) < ...
MapSorter.Support.sortable(&2[:likes]) -> ...
"""
Returns a sort function based on the given sort specs
.
Examples
iex> alias MapSorter.Support
iex> Logger.configure(level: :info) # :debug → debug messages
iex> sort_fun = Support.eval_sort_fun([:dob, desc: :likes])
iex> Logger.configure(level: :info) # :info → no debug messages
iex> is_function(sort_fun, 2)
true
Link to this function
sort_fun_ast(sort_specs)
View Source
sort_fun_ast([sort_spec()] | {any(), any(), any()}) :: {any(), any(), any()}
Returns the AST of a sort function based on the given sort specs
(compile time or runtime).
Examples
iex> alias MapSorter.Support
iex> Logger.configure(level: :info) # :debug → debug messages
iex> sort_fun_ast = Support.sort_fun_ast([:dob, desc: :likes])
iex> Logger.configure(level: :info) # :info → no debug messages
iex> match?({:&, _meta, _args}, sort_fun_ast)
true
iex> alias MapSorter.Support
iex> sort_specs_ast = quote do: Tuple.to_list({:dob, {:desc, :likes}})
iex> Logger.configure(level: :info) # :debug → debug messages
iex> sort_fun_ast = Support.sort_fun_ast(sort_specs_ast)
iex> Logger.configure(level: :info) # :info → no debug messages
iex> match?({{:., _, _}, _meta, _args}, sort_fun_ast)
true