Last active
February 9, 2016 16:17
-
-
Save sashaafm/4b2f9d132ba0d2923986 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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