Author: Bert Peters (bert.ljpeters@gmail.com)
 /**
  * Test the Functions::combine method.
  */
 public function testCombine()
 {
     $a = function ($value) {
         return $value + 2;
     };
     $b = function ($value) {
         return $value * 3;
     };
     $result = Functions::combine($a, $b);
     $this->assertTrue(is_callable($result), 'Combined function should be callable.');
     $this->assertEquals($result(3), 15);
 }
Exemple #2
0
 /**
  * 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);
 }