Skip to content

Instantly share code, notes, and snippets.

@hagiyat
Last active August 29, 2015 14:27
Show Gist options
  • Save hagiyat/ac9ef191164b63429ffc to your computer and use it in GitHub Desktop.
Save hagiyat/ac9ef191164b63429ffc to your computer and use it in GitHub Desktop.
search by key from flat list
def search(key, list) do
list
|> Enum.split(2) # convert list to key/value
|> Tuple.to_list
|> Enum.filter_map(fn(v) -> v |> List.first == key end, &(&1 |> List.last))
|> List.first
end
search("hoge", ["hoge", 1, "fuga", 2, "piyo", "baz"]) # 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment