Skip to content

Instantly share code, notes, and snippets.

View ggb's full-sized avatar

Gregor ggb

  • Kiel
View GitHub Profile
defmodule SleepSort do
def sort(list_of_numbers) do
{:ok, sorted_list} = Agent.start(fn -> [] end)
Enum.map(list_of_numbers, fn number ->
Task.start(fn ->
:timer.sleep(number * 1)
Agent.update(sorted_list, fn l -> [ number | l ] end)
end)
defmodule DataMuging do
def processLines [], result, _cols do
result
end
def processLines [head | tail], result, { fst, scd, thd } do
if Regex.match?(%r/^\s*\d+.?\s+/, head) do
s = String.split head
processLines tail, [ { Enum.at(s, fst),