Skip to content

Instantly share code, notes, and snippets.

@azjezz
Created April 24, 2019 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azjezz/3a00121711ae30a6dac3a172b502b246 to your computer and use it in GitHub Desktop.
Save azjezz/3a00121711ae30a6dac3a172b502b246 to your computer and use it in GitHub Desktop.
```
use namespace HH\Lib\Vec;
function process(
vec<(string, string, string, string)> $input
): dict<string, dict<string, dict<string, vec<string>>> {
$result = dict[];
foreach($input as $tuple) {
$result[$tuple[0]][$tuple[1]][$tuple[2]] = Vec\concat(
$result[$tuple[0]][$tuple[1]][$tuple[2]] ?? vec[],
vec[$tuple[3]],
);
}
return $result;
}
<<__EntryPoint>>
async function main(): Awaitable<void> {
$data = vec[
tuple('sam', 'john', 'tim', 'tom'),
tuple('sam', 'john', 'tim', 'dom'),
tuple('sam', 'john', 'jim', 'ryan'),
tuple('sam', 'john', 'jim', 'bryan'),
tuple('sam', 'oscar', 'kim', 'mike'),
tuple('sam', 'oscar', 'kim', 'ike'),
tuple('sam', 'oscar', 'liz', 'jared'),
tuple('sam', 'oscar', 'liz', 'jay'),
tuple('will', 'ann', 'ray', 'jill'),
tuple('will', 'ann', 'ray', 'phil'),
tuple('will', 'ann', 'abe', 'henry'),
tuple('will', 'ann', 'abe', 'jackie'),
tuple('will', 'don', 'clive', 'katie'),
tuple('will', 'don', 'clive', 'bill'),
tuple('will', 'don', 'hank', 'sherlock'),
tuple('will', 'don', 'hank', 'bruce'),
]
|> process($$)
|> \json_encode($$);
\var_dump($data);
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment