public function testTap() { // from js $intercepted = null; $interceptor = function ($obj) use(&$intercepted) { $intercepted = $obj; }; $returned = __u::tap(1, $interceptor); $this->assertEquals(1, $intercepted, 'passed tapped object to interceptor'); $this->assertEquals(1, $returned, 'returns tapped object'); $returned = __u(array(1, 2, 3))->chain()->map(function ($n) { return $n * 2; })->max()->tap($interceptor)->value(); $this->assertTrue($returned === 6 && $intercepted === 6, 'can use tapped objects in a chain'); $returned = __u::chain(array(1, 2, 3))->map(function ($n) { return $n * 2; })->max()->tap($interceptor)->value(); $this->assertTrue($returned === 6 && $intercepted === 6, 'can use tapped objects in a chain with static call'); // docs $interceptor = function ($obj) { return $obj * 2; }; $result = __u(array(1, 2, 3))->chain()->max()->tap($interceptor)->value(); $this->assertEquals(3, $result); }