Just to illustrate how to achieve the bi-directional structure you were looking for.
defmodule Pitch do
list = [
# flats are preferrable to sharps (jazz musician here)
{"C", 0},
{"D", 2},
{"E", 4},
{"F", 5},
{"G", 7},
{"A", 9},
{"B", 1},
{"Db", 1},
{"Gb", 6},
{"Ab", 8},
{"Bb", 10},
{"Eb", 3},
{"C#", 1},
{"D#", 3},
{"G#", 8},
{"A#", 10},
{"F#", 6},
# these are just weird, so they exist only as aliases for B/C E/F respectively.
{"Fb", 4},
{"E#", 5},
{"B#", 0},
{"Cb", 11}
]
map = Enum.into(list, %{})
@two_way_map Enum.reduce(list, map, fn {k, v}, acc -> Map.put_new(acc, v, k) end)
def two_way_map(key) when is_binary(key) or is_integer(key) do
Map.get(@two_way_map, key)
end
end
iex(1)> Pitch.two_way_map("A#")
10
iex(2)> Pitch.two_way_map(10)
"Bb"
iex(3)> Pitch.two_way_map(110)
nil


















