Skip to content

Instantly share code, notes, and snippets.

@sashaafm
Last active February 9, 2016 16:17
Show Gist options
  • Save sashaafm/4b2f9d132ba0d2923986 to your computer and use it in GitHub Desktop.
Save sashaafm/4b2f9d132ba0d2923986 to your computer and use it in GitHub Desktop.
def increase_element_priority([], _, _), do: []
def increase_element_priority(queue, {item, prio} = elem, new_prio)
when new_prio >= prio do
pos = position_by_order queue, elem
first_half = (queue |> Enum.take(pos)) -- [elem]
sec_half = queue |> Enum.slice(pos, length(queue))
first_half ++ [{item, new_prio}] ++ sec_half
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment