/** * Test the Functions::identity method. */ public function testIdentity() { $data = ['foo', 'bar', 42]; $identityFunc = Functions::identity(); $this->assertTrue(is_callable($identityFunc), "Identity function should be callable."); foreach ($data as $item) { $this->assertEquals($item, $identityFunc($item)); } }
/** * Flatten the underlying stream. * * This method takes each element and unpacks it into a sequence of elements. * All individual sequences are concatenated in the resulting stream. * * @param callable $unpacker [optional] An unpacker function that can unpack * elements into something iterable. Default is to use the identity function. * @return Stream */ public function flatMap(callable $unpacker = null) { if ($unpacker == null) { $unpacker = Functions::identity(); } return new FlatMapOperation($this, $unpacker); }