ecto_playlist v0.0.1 EctoPlaylist.ListItem View Source

Implements conveniences to change the items order of a list.

Link to this section Summary

Functions

Check if list item id is the first element in the ordering.

Return the list item id which is one rank higher in the ordering.

Return the list of ids above the list item id.

Check if list item id is in the ordering.

Insert an list item id in the given index of an order_list

Check if list item id is the last element in the ordering.

Return the list item id which is one rank lower in the ordering.

Return the list of ids below the list item id.

Move the list item id one rank higher in the ordering.

Move the list item id one rank lower in the ordering.

Move the list item id at the last position in the ordering.

Move the list item id at the first position in the ordering.

Check if list item id is in the ordering.

Remove the list item id in the ordering.

Link to this section Functions

Link to this function

first?(order_list, list_item) View Source

Check if list item id is the first element in the ordering.

iex> EctoPlaylist.ListItem.first?([1, 2, 3, 4], 1)
true

iex> EctoPlaylist.ListItem.first?([1, 2, 3, 4], 3)
false

iex> EctoPlaylist.ListItem.first?([1, 2, 3, 4], 5)
false
Link to this function

higher_item(order_list, list_item) View Source

Return the list item id which is one rank higher in the ordering.

iex> EctoPlaylist.ListItem.higher_item([1, 7, 3, 4], 3)
7

iex> EctoPlaylist.ListItem.higher_item([1, 2, 3, 4], 1)
nil

iex> EctoPlaylist.ListItem.higher_item([1, 2, 3, 4], 5)
nil
Link to this function

higher_items(order_list, list_item) View Source

Return the list of ids above the list item id.

iex> EctoPlaylist.ListItem.higher_items([1, 2, 3, 4], 3)
[1, 2]

iex> EctoPlaylist.ListItem.higher_items([1, 2, 3, 4], 4)
[1, 2, 3]

iex> EctoPlaylist.ListItem.higher_items([1, 2, 3, 4], 1)
[]

iex> EctoPlaylist.ListItem.higher_items([1, 2, 3, 4], 5)
nil
Link to this function

in_list?(order_list, list_item) View Source

Check if list item id is in the ordering.

iex> EctoPlaylist.ListItem.in_list?([1, 2, 3, 4], 3)
true

iex> EctoPlaylist.ListItem.in_list?([1, 2, 3, 4], 5)
false
Link to this function

insert_at(order_list, list_item, index) View Source

Insert an list item id in the given index of an order_list

iex> EctoPlaylist.ListItem.insert_at([1, 2, 3, 4], 9, 2)
[1, 9, 2, 3, 4]

iex> EctoPlaylist.ListItem.insert_at([1, 2, 3], 9, 10)
[1, 2, 3, 9]

iex> EctoPlaylist.ListItem.insert_at([1, 2, 9, 3], 9, 2)
[1, 9, 2, 3]

iex> EctoPlaylist.ListItem.insert_at([1, 2, 9, 3], 9, 10)
[1, 2, 3, 9]

iex> EctoPlaylist.ListItem.insert_at([1, 2, 9, 3], 9, nil)
[1, 2, 9, 3]
Link to this function

last?(order_list, list_item) View Source

Check if list item id is the last element in the ordering.

iex> EctoPlaylist.ListItem.last?([1, 2, 3, 4], 4)
true

iex> EctoPlaylist.ListItem.last?([1, 2, 3, 4], 2)
false

iex> EctoPlaylist.ListItem.last?([1, 2, 3, 4], 5)
false
Link to this function

lower_item(order_list, list_item) View Source

Return the list item id which is one rank lower in the ordering.

iex> EctoPlaylist.ListItem.lower_item([1, 2, 3, 7], 3)
7

iex> EctoPlaylist.ListItem.lower_item([1, 2, 3, 4], 4)
nil

iex> EctoPlaylist.ListItem.lower_item([1, 2, 3, 4], 5)
nil
Link to this function

lower_items(order_list, list_item) View Source

Return the list of ids below the list item id.

iex> EctoPlaylist.ListItem.lower_items([1, 2, 3, 4], 2)
[3, 4]

iex> EctoPlaylist.ListItem.lower_items([1, 2, 3, 4], 1)
[2, 3, 4]

iex> EctoPlaylist.ListItem.lower_items([1, 2, 3, 4], 4)
[]

iex> EctoPlaylist.ListItem.lower_items([1, 2, 3, 4], 5)
nil
Link to this function

move_higher(order_list, list_item) View Source

Move the list item id one rank higher in the ordering.

iex> EctoPlaylist.ListItem.move_higher([1, 2, 3, 4], 3)
[1, 3, 2, 4]

iex> EctoPlaylist.ListItem.move_higher([1, 2, 3, 4], 1)
[1, 2, 3, 4]

iex> EctoPlaylist.ListItem.move_higher([1, 2, 3, 4], 5)
[1, 2, 3, 4]
Link to this function

move_lower(order_list, list_item) View Source

Move the list item id one rank lower in the ordering.

iex> EctoPlaylist.ListItem.move_lower([1, 2, 3, 4], 3)
[1, 2, 4, 3]

iex> EctoPlaylist.ListItem.move_lower([1, 2, 3, 4], 1)
[2, 1, 3, 4]

iex> EctoPlaylist.ListItem.move_lower([1, 2, 3, 4], 4)
[1, 2, 3, 4]

iex> EctoPlaylist.ListItem.move_lower([1, 2, 3, 4], 5)
[1, 2, 3, 4]
Link to this function

move_to_bottom(order_list, list_item) View Source

Move the list item id at the last position in the ordering.

iex> EctoPlaylist.ListItem.move_to_bottom([1, 2, 3, 4], 3)
[1, 2, 4, 3]

iex> EctoPlaylist.ListItem.move_to_bottom([1, 2, 3, 4], 1)
[2, 3, 4, 1]

iex> EctoPlaylist.ListItem.move_to_bottom([1, 2, 3, 4], 4)
[1, 2, 3, 4]

iex> EctoPlaylist.ListItem.move_to_bottom([1, 2, 3, 4], 5)
[1, 2, 3, 4, 5]
Link to this function

move_to_top(order_list, list_item) View Source

Move the list item id at the first position in the ordering.

iex> EctoPlaylist.ListItem.move_to_top([1, 2, 3, 4], 3)
[3, 1, 2, 4]

iex> EctoPlaylist.ListItem.move_to_top([1, 2, 3, 4], 1)
[1, 2, 3, 4]

iex> EctoPlaylist.ListItem.move_to_top([1, 2, 3, 4], 5)
[5, 1, 2, 3, 4]
Link to this function

not_in_list?(order_list, list_item) View Source

Check if list item id is in the ordering.

iex> EctoPlaylist.ListItem.not_in_list?([1, 2, 3, 4], 5)
true

iex> EctoPlaylist.ListItem.not_in_list?([1, 2, 3, 4], 3)
false
Link to this function

remove_from_list(order_list, list_item) View Source

Remove the list item id in the ordering.

iex> EctoPlaylist.ListItem.remove_from_list([1, 2, 3, 4], 3)
[1, 2, 4]

iex> EctoPlaylist.ListItem.remove_from_list([1, 2, 3, 4], 1)
[2, 3, 4]

iex> EctoPlaylist.ListItem.remove_from_list([1, 2, 3, 4], 5)
[1, 2, 3, 4]