1717use Koded \Stdlib \Serializer \{JsonSerializer , XmlSerializer };
1818use RecursiveDirectoryIterator ;
1919use RecursiveIteratorIterator ;
20+ use stdClass ;
2021use function array_diff_assoc ;
2122use function array_key_exists ;
2223use function array_product ;
@@ -57,9 +58,9 @@ function arguments(...$values): Argument
5758 * with optional arbitrary number of arguments.
5859 *
5960 * @param array ...$values
60- * @return Argument
61+ * @return ExtendedArguments
6162 */
62- function extended_arguments (...$ values ): Argument
63+ function extended (...$ values ): ExtendedArguments
6364{
6465 return new ExtendedArguments (...$ values );
6566}
@@ -76,6 +77,31 @@ function value(...$values): Data
7677 return new Immutable (...$ values );
7778}
7879
80+ /**
81+ * Do something with an object or array inside the callable,
82+ * and return that value.
83+ *
84+ * @param mixed $value The value that is tapped into the callback
85+ * @param callable|null $callable Callback that can modify the value
86+ * @return mixed The tapped value
87+ */
88+ function tap (mixed $ value , callable $ callable = null ): mixed
89+ {
90+ if (false === is_null ($ callable )) {
91+ $ callable ($ value );
92+ return $ value ;
93+ }
94+ return new class ($ value ) extends stdClass implements Tapped {
95+ public function __construct (private mixed $ value ) {}
96+ public function __call ($ method , $ arguments ) {
97+ // @codeCoverageIgnoreStart
98+ $ this ->value ->{$ method }(...$ arguments );
99+ return $ this ->value ;
100+ // @codeCoverageIgnoreEnd
101+ }
102+ };
103+ }
104+
79105/**
80106 * Transforms simple CamelCaseName into camel_case_name (lower case underscored).
81107 *
0 commit comments