Skip to content

Instantly share code, notes, and snippets.

@wang-zhijun
Last active March 16, 2016 14:00
Show Gist options
  • Save wang-zhijun/18e5b5aaca621ce36784 to your computer and use it in GitHub Desktop.
Save wang-zhijun/18e5b5aaca621ce36784 to your computer and use it in GitHub Desktop.
ElixirとErlangの間の変換

Erlang, Elixir間の変換

Erlang

1> element(2, {a, b, c}). %% インデックスは1ベース
b

Elixir

iex(1)> elem({:a,:b,:c}, 1)  ## インデックスは0ベース
:c

Erlang

catchのElixirの中での書き方参照リンク

rawSamples = [ catch element(2, {struct,_}=mochijson2:decode(V)) || || V <- riakc_obj:get_values(Object) ]

Elixir

## objectの例 object = "{\"job\": {\"id\": \"1\"}}"
rawSamples =  for v <- :riakc_obj.get_values(object) do
                try do
                  elem({:struct, _} = :mochijson2.decode(v), 1)
                catch
                  error, reason ->
                    {error, reason}
                end
              end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment