forked from KiaraGrouwstra/pquery
-
Notifications
You must be signed in to change notification settings - Fork 9
/
List.Zip.pq
29 lines (27 loc) · 798 Bytes
/
List.Zip.pq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
//Zip a list of lists so as to 'transpose' them -- as records if names are specified.
//Usage:
List.Zip = Load("List.Zip"),
List.Zip({{1,2,3},{"a","b","c"}}, {"num","let"})
//Result: {[num=1, let="a"],[num=2, let="b"],[num=3, let="c"]}
*/
(listOfLists as list, optional names as list) as list =>
let
max = List.Max(List.Transform(listOfLists, each List.Count(_))),
zipped = List.Skip(List.Generate(
()=>[
i = -1,
vals = {},
combined = {}
],
each [i] < max,
each [
i = [i] + 1,
vals = List.Transform(listOfLists, each _{i}),
combined = if names = null then vals else Record.FromList(vals, names)
],
each [combined]
)),
tablized = Table.FromRecords(zipped) //Table.FromRows
in
tablized