Created
March 19, 2016 08:48
-
-
Save hagiyat/8194576eeb25b4bec7d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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