This repository has been archived on 2023-08-07. You can view files and clone it, but cannot push or open issues or pull requests.
temple/lib/buffer.ex
Mitchell Hanberg 33c95186fb
Compile to EEx (#80)
Code is gross
2020-06-16 15:28:21 -04:00

32 lines
529 B
Elixir

defmodule Temple.Buffer do
@moduledoc false
def start_link(state \\ []) do
Agent.start_link(fn -> state end)
end
def put(buffer, value) do
Agent.update(buffer, fn b -> [value | b] end)
end
def remove_new_line(buffer) do
Agent.update(buffer, fn
["\n" | rest] ->
rest
rest ->
rest
end)
end
def get(buffer) do
buffer
|> Agent.get(& &1)
|> Enum.reverse()
|> Enum.join()
|> String.trim()
end
def stop(buffer) do
Agent.stop(buffer)
end
end