Functions for working with trees.
<?php
use function Php\Immutable\Fs\Trees\trees\mkdir;
use function Php\Immutable\Fs\Trees\trees\mkfile;
use function Php\Immutable\Fs\Trees\trees\getName;
use function Php\Immutable\Fs\Trees\trees\isDirectory;
use function Php\Immutable\Fs\Trees\trees\isFile;
use function Php\Immutable\Fs\Trees\trees\map;
isFile(mkfile('config')); // true
isDirectory(mkdir('etc')); // true
$tree = mkdir('etc', [mkfile('config'), mkfile('hosts')]);
map(fn($node) => array_merge($node, ['name' => strtoupper(getName($node))]), $tree);
// [
// name => 'ETC',
// children => [
// [ name => 'CONFIG', meta => [], type => 'file' ],
// [ name => 'HOSTS', meta => [], type => 'file' ]
// ],
// meta => [],
// type => 'directory'
// ]
This repository is created and maintained by the team and the community of Hexlet, an educational project. Read more about Hexlet.
See most active contributors on hexlet-friends.