MapSorter.Compare (Map Sorter v0.2.45) View Source
Generates a compare function from a list of sort specs
.
Link to this section Summary
Functions
Generates a compare function from a list of sort specs
.
Generates a compare function as a heredoc from a list of sort specs
.
Link to this section Types
Specs
fun() :: (Access.container(), Access.container() -> boolean())
Link to this section Functions
Specs
fun(MapSorter.SortSpecs.t()) :: (... -> any())
Generates a compare function from a list of sort specs
.
Examples
iex> alias MapSorter.Compare
iex> sort_specs = [:dob, desc: :likes]
iex> fun = Compare.fun(sort_specs)
iex> is_function(fun, 2)
true
Specs
heredoc(MapSorter.SortSpecs.t()) :: String.t()
Generates a compare function as a heredoc from a list of sort specs
.
Examples
iex> alias MapSorter.Compare
iex> Compare.heredoc([])
"""
& cond do
true -> true or &1 * &2
end
"""
iex> alias MapSorter.Compare
iex> sort_specs = [:name, {:desc, :dob}]
iex> Compare.heredoc(sort_specs)
"""
& cond do
&1[:name] < &2[:name] -> true
&1[:name] > &2[:name] -> false
&1[:dob] > &2[:dob] -> true
&1[:dob] < &2[:dob] -> false
true -> true or &1 * &2
end
"""
iex> alias MapSorter.Compare
iex> sort_specs = [:name, {:desc, {:dob, Date}}]
iex> Compare.heredoc(sort_specs)
"""
& cond do
&1[:name] < &2[:name] -> true
&1[:name] > &2[:name] -> false
&1[:dob] != nil and Date.compare(&1[:dob], &2[:dob]) == :gt -> true
&1[:dob] != nil and Date.compare(&1[:dob], &2[:dob]) == :lt -> false
true -> true or &1 * &2
end
"""