MapSorter.Cond (Map Sorter v0.2.46) View Source

Generates cond clauses as a heredoc from a list of sort specs.

Link to this section Summary

Functions

Generates cond clauses as a heredoc from a list of sort specs.

Link to this section Functions

Specs

Generates cond clauses as a heredoc from a list of sort specs.

Examples

iex> alias MapSorter.Cond
iex> sort_specs = [:name, {:desc, :dob}]
iex> Cond.clauses(sort_specs)
"""
&1[:name] < &2[:name] -> true
&1[:name] > &2[:name] -> false
&1[:dob] > &2[:dob] -> true
&1[:dob] < &2[:dob] -> false
"""

iex> alias MapSorter.Cond
iex> sort_specs = [:name, {:desc, {:dob, Date}}]
iex> Cond.clauses(sort_specs)
"""
&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
"""