Skip to content

Instantly share code, notes, and snippets.

@hagiyat
Created March 19, 2016 08:48
Show Gist options
  • Save hagiyat/8194576eeb25b4bec7d2 to your computer and use it in GitHub Desktop.
Save hagiyat/8194576eeb25b4bec7d2 to your computer and use it in GitHub Desktop.
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