我有一个变量设置为player_id
,它是一个随机的uuid。但它匹配17个不同地图中的1个。我希望能够将变量与其他映射匹配并返回匹配的映射。我怎样才能在Elixir中实现这一目标?
当前尝试和数据:
%{"abbr_name" => "R.Baker", "birth_place" => "Scott City, KS, USA",
"birthdate" => "1993-03-30", "college" => "Wichita State",
"experience" => "1", "first_name" => "Ron", "full_name" => "Ron Baker",
"height" => 76, "id" => "e8c0b33f-43b3-4490-865f-ed919d015bb2",
"jersey_number" => "31", "last_name" => "Baker", "position" => "G",
"primary_position" => "SG", "reference" => "1627758", "status" => "ACT",
"updated" => "2017-11-28T22:37:19+00:00", "weight" => 220},
%{"abbr_name" => "L.Thomas", "birth_place" => "Brooklyn, NY, USA",
"birthdate" => "1988-04-24", "college" => "Duke",
"draft" => %{"year" => 2010}, "experience" => "6", "first_name" => "Lance",
"full_name" => "Lance Thomas", "height" => 80,
"id" => "f76acd63-bf42-4fa7-9985-a7838f9cb029", "jersey_number" => "42",
"last_name" => "Thomas", "position" => "F", "primary_position" => "SF",
"reference" => "202498", "status" => "ACT",
"updated" => "2017-10-17T19:37:09+00:00", "weight" => 235},
%{"abbr_name" => "L.Kornet", "birth_place" => "Lexington, KY, USA",
"birthdate" => "1995-07-15", "college" => "Vanderbilt",
"draft" => %{"year" => 2017}, "experience" => "0", "first_name" => "Luke",
"full_name" => "Luke Kornet", "height" => 85,
"id" => "fed6929f-8d92-456c-8a89-9e0c17cf4f7b", "jersey_number" => "2",
"last_name" => "Kornet", "position" => "C-F", "primary_position" => "C",
"reference" => "1628436", "status" => "D-LEAGUE",
"updated" => "2017-10-17T19:37:09+00:00", "weight" => 250}
player_id设为e8c0b33f-43b3-4490-865f-ed919d015bb2
了解其中一个ID与player_id
的匹配程度?如何将两者相匹配并对其进行范围以使其返回:
%{"abbr_name" => "R.Baker", "birth_place" => "Scott City, KS, USA",
"birthdate" => "1993-03-30", "college" => "Wichita State",
"experience" => "1", "first_name" => "Ron", "full_name" => "Ron Baker",
"height" => 76, "id" => "e8c0b33f-43b3-4490-865f-ed919d015bb2",
"jersey_number" => "31", "last_name" => "Baker", "position" => "G",
"primary_position" => "SG", "reference" => "1627758", "status" => "ACT",
"updated" => "2017-11-28T22:37:19+00:00", "weight" => 220}
只有与player_id匹配的id的完整播放器地图?
答案 0 :(得分:2)
根据某些条件,您有一个地图列表,并且您希望获得其中一个地图。在这种情况下,您希望检索那个"id"
与您的player_id
对应的地图。
在这种情况下,你可以简单地做:
Enum.find(your_17_maps_as_a_list, fn %{"id" => id} -> player_id == id end)
如果您可能有多个具有相同ID的地图,并且您需要检索所有这些地图,请使用Enum.filter