Created
April 24, 2019 08:34
-
-
Save azjezz/3a00121711ae30a6dac3a172b502b246 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
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