आप या तो खेतों मैन्युअल
defmodule Test do
def foo(%User{name: name, twitter: twitter}, {User, name, twitter}) do
IO.puts "match :)"
end
def foo(_struct, _record) do
IO.puts "no match :("
end
end
मैच के लिए की जरूरत है या आप इसे एक struct पहले में बदलने और फिर दो
defmodule Test do
def foo(struct, record) do
do_foo struct, user_record_to_struct(record)
end
defp user_record_to_struct({User, name, twitter}) do
%User{name: name, twitter: twitter}
end
defp do_foo(struct, struct) do
IO.puts "match :)"
end
defp do_foo(_struct1, _struct2) do
IO.puts "no match :("
end
end
स्रोत
2015-05-28 06:08:43
से मेल खाते हैं जब से तुम साथ "AFAIK" शुरू कर दिया की जरूरत है , मैं सिर्फ यह पुष्टि करना चाहता हूं कि यह उत्तर बिल्कुल सही है। :) –
धन्यवाद, @ जोसेवलिम ने इसे हटा दिया ;-) –