1 | <?php |
||
16 | class Recursor extends FSObject |
||
17 | { |
||
18 | 1 | use FilterTrait; |
|
19 | |||
20 | /** |
||
21 | * @var FixedFDirectory |
||
22 | */ |
||
23 | protected $directory; |
||
24 | |||
25 | 16 | public function __construct(FixedFDirectory $directory) |
|
30 | |||
31 | /** |
||
32 | * Get a recursor that folds all files in this recursor that match the |
||
33 | * provided predicate and the objects below that match the predicate as |
||
34 | * well. |
||
35 | * |
||
36 | * Won't recurse over directories that do not match the predicate! |
||
37 | * |
||
38 | * @param \Closure $predicate (FSObject -> Bool) |
||
39 | */ |
||
40 | 8 | public function filter(\Closure $predicate) : Recursor |
|
55 | |||
56 | /** |
||
57 | * We could also use the catamorphism on this to do recursion, as we |
||
58 | * have an unfix and an underlying fmap from the FDirectory. |
||
59 | * |
||
60 | * Supply a function $trans from File|FDirectory a to a that flattens |
||
61 | * (folds) a directory. Will start the directories where only files are |
||
62 | * included, folds them and then proceeds upwards. |
||
63 | * |
||
64 | * The return type should be 'a' (from the function $trans) instead |
||
65 | * of mixed, but we can't express that fact correctly in the docstring |
||
66 | * typing. |
||
67 | * |
||
68 | * @param \Closure $trans File|FDirectory a -> a |
||
69 | * @return mixed |
||
70 | */ |
||
71 | 16 | public function cata(\Closure $trans) |
|
81 | |||
82 | /** |
||
83 | * Sugar for cata. |
||
84 | * |
||
85 | * @param \Closure $trans File|FDirectory a -> a |
||
86 | * @return mixed |
||
87 | */ |
||
88 | 4 | public function with(\Closure $trans) |
|
92 | |||
93 | /** |
||
94 | * Fold over all files in this directory and subjacent directories. |
||
95 | * |
||
96 | * Start with an initial value of some type and a function from that type |
||
97 | * and File to a new value of the type. Will successively feed all files |
||
98 | * and the resulting values to that function. |
||
99 | * |
||
100 | * @param mixed $start_value |
||
101 | * @param \Closure $fold_with a -> File -> a |
||
102 | * @return Recursor|array |
||
103 | */ |
||
104 | 6 | public function foldFiles($start_value, \Closure $fold_with) |
|
111 | |||
112 | /** |
||
113 | * Get a list of all files in the directory and subjacent directories. |
||
114 | * |
||
115 | * @return File[] |
||
116 | */ |
||
117 | 10 | public function allFiles() : array |
|
132 | |||
133 | |||
134 | /** |
||
135 | * @inheritdoc |
||
136 | */ |
||
137 | public function isFile() : bool |
||
141 | } |
||
142 |