Author: Bert Peters (bert.ljpeters@gmail.com)
Ejemplo n.º 1
0
 /**
  * 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);
 }
Ejemplo n.º 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);
 }