/** * Maps over a Seq who's $hof function returns a FoldableInterface or array and flattens the result * into a single sequence. * @param callable $hof ($value, $key, $this) -> FoldableInterface|SplFixedArray|ArrayObject|ArrayIterator|array * @return Seq */ public function flatMap(callable $hof) { $output = []; foreach (I($this->hash) as $key => $value) { $intermediate = call_user_func($hof, $value, $key, $this); $array = __PRIVATE__::getArrayFrom($intermediate); $output[] = $array !== null ? $array : __CONTRACT__::returnIsA(FoldableInterface::class, $intermediate); } return static::from(call_user_func_array('array_merge', $output)); }
/** * @covers ::returnIsA */ public function test_returnIsA_exception() { $this->expectException(invalidReturn::class); contract::returnIsA(\stdClass::class, function () { }); }