hexlet/trees

v1.1.0 2022-01-16 12:54 UTC

This package is not auto-updated.

Last update: 2024-04-21 23:27:51 UTC


README

github action status

Functions for working with trees.

Examples

<?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'
// ]

Hexlet Ltd. logo

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.