在Elixir中,我有这张地图
my_map = [%{ user_id: 1, user_name: "David", gamer_id: 100, gamer_name: "John" },
%{ user_id: 1, user_name: "David", gamer_id: 101, gamer_name: "Bil" },
%{ user_id: 1, user_name: "David", gamer_id: 103, gamer_name: "Ruk" },
%{ user_id: 2, user_name: "Ron", gamer_id: 104, gamer_name: "Sam" },
%{ user_id: 2, user_name: "Ron", gamer_id: 105, gamer_name: "Sean" }]
我想将其转换为以下输出
输出:
[%{ user_id: 1, username: "David",
games: [
%{
gamer_id: 100,
gamer_name: "John"
},
%{
gamer_id: 101,
gamer_name: "Bil"
},
%{
gamer_id: 103,
gamer_name: "Ruk"
}
]
},
%{ user_id: 2, username: "Ron",
games: [
%{
gamer_id: 104,
gamer_name: "Sam"
},
%{
gamer_id: 105,
gamer_name: "Sean"
}
]
}]
我尝试了Enum.group_by,但全部都无法实现
my_map |> Enum.group_by(fn(x)-> x.user_id结尾)
任何对实现这一目标的见识将不胜感激。
答案 0 :(得分:2)
您可以使用<UserControl d:DesignHeight="450" d:DesignWidth="794">
<DockPanel DataContext="{Binding Model1}">
<GroupBox Header="{concept:Intl Key=Geometry, DefaultText='G1'}" DockPanel.Dock="Top" MinHeight="165">
<Grid>
// Common view
</Grid>
</GroupBox>
<GroupBox DockPanel.Dock="Bottom" Header="{concept:Intl Key=G2, DefaultText='G2'}" DataContext="{Binding G2}" Padding="0,10">
<Grid>
// other stuff
</Grid>
</GroupBox>
</DockPanel>
的第三个参数来提取git revert {commit_id}
和Enum.group_by
,然后使用gamer_id
进行一些处理:
gamer_name
输出:
Enum.map