/** * conj one or more goals without nesting. */ function conjPlus($g) { $gs = func_get_args(); if (func_num_args() === 1) { return zzz($g); } else { return conj(zzz($g), call_user_func_array('MicroKanren\\Core\\conjPlus', array_slice($gs, 1))); } }
/** * Return a map of elements of coll keyed by result of f on each element. * f can be a key. */ function group_by($f, array $arr) { return reduce(function ($grouped, $arg) use($f) { $val = function_exists($f) ? $f($arg) : $arg[$f]; if (!isset($grouped[$val])) { $grouped[$val] = []; } $grouped[$val] = conj($grouped[$val], $arg); return $grouped; }, $arr, []); }
function relo($x) { return callFresh(function ($x1) use($x) { return callFresh(function ($x2) use($x, $x1) { return conj(eq($x, cons($x1, $x2)), disj(eq($x1, $x2), function ($sC) use($x) { return function () use($x, $sC) { $r = relo($x); return $r($sC); }; })); }); }); }