Flop.push_order

You're seeing just the function push_order, go back to Flop module for more information.
Link to this function

push_order(flop, field)

View Source (since 0.10.0)

Specs

push_order(t(), atom()) :: t()

Updates the order_by and order_directions values of a Flop struct.

  • If the field is not in the current order_by value, it will be prepended to the list. The order direction for the field will be set to :asc.
  • If the field is already at the front of the order_by list, the order direction will be reversed.
  • If the field is already in the list, but not at the front, it will be moved to the front and the order direction will be set to :asc.

Example

iex> flop = push_order(%Flop{}, :name)
iex> flop.order_by
[:name]
iex> flop.order_directions
[:asc]
iex> flop = push_order(flop, :age)
iex> flop.order_by
[:age, :name]
iex> flop.order_directions
[:asc, :asc]
iex> flop = push_order(flop, :age)
iex> flop.order_by
[:age, :name]
iex> flop.order_directions
[:desc, :asc]
iex> flop = push_order(flop, :species)
iex> flop.order_by
[:species, :age, :name]
iex> flop.order_directions
[:asc, :desc, :asc]
iex> flop = push_order(flop, :age)
iex> flop.order_by
[:age, :species, :name]
iex> flop.order_directions
[:asc, :asc, :asc]