#TIR: Build a Simple Persistent Key-Value Store in Elixir, using Logs - Part 1

github logo ・1 min read

link-->

Today I read it from Awesome Elixir Newsletter. Nice for learning Elixir.

def lookup(key) do
  GenServer.call(__MODULE__, {:lookup, key})
end

def handle_call({:lookup, key}, _from, index_map) do
  {:reply, get_key_offset_size(key, index_map), index_map}
end

defp get_key_offset_size(key, index_map) do
  case Map.get(index_map, key) do
    {_offset, _size} = offset_size -> {:ok, offset_size}
    nil -> {:error, :not_found}
  end
end
twitter logo DISCUSS
Classic DEV Post from Oct 17

5 Useful VSCode Extensions for Live Coding

chenge profile image
Ruby, and learn Rust, Go, Elixir, Erlang...

Sore eyes?

dev.to now has dark mode (in public beta).

Go to the "misc" section of your settings and select night theme ❀️