/** * We could also use the catamorphism on this to do recursion, as we * have an unfix and an underlying fmap from the FDirectory. * * Supply a function $trans from File|FDirectory a to a that flattens * (folds) a directory. Will start the directories where only files are * included, folds them and then proceeds upwards. * * The return type should be 'a' (from the function $trans) instead * of mixed, but we can't express that fact correctly in the docstring * typing. * * @param \Closure $trans File|FDirectory a -> a * @return mixed */ public function cata(\Closure $trans) { return $trans($this->directory->unfix()->fmap(function (FSObject $obj) use($trans) { if ($obj->isFile()) { return $trans($obj); } assert($obj instanceof FixedFDirectory); return $obj->cata($trans); })); }