Exemplo n.º 1
0
 public function __invoke(...$data)
 {
     $arr = $data[0];
     $sum = MathNode::sum();
     return $sum($arr) / count($arr);
 }
Exemplo n.º 2
0
 public function testSum()
 {
     $data = [8, 5, 7, 2, 3];
     $node = MathNode::sum();
     $this->assertEquals(25, $node($data));
 }
Exemplo n.º 3
0
 public function testSortMapMap()
 {
     $data = [['4354', '54', '52'], ['45675', '435', '234223'], ['4354', '54']];
     $node = _Array::sort(_Comparator::boolean()->map(MathNode::sum())->map(_Filter::isEven()));
     $this->assertEquals([['45675', '435', '234223'], ['4354', '54', '52'], ['4354', '54']], $node($data));
 }
Exemplo n.º 4
0
abstract class AbstractArray extends AbstractNode implements CollectionNodeInterface
{
    /**
     * @param callable $do
     * @return AbstractNode
     */
    public function then(callable $do)
    {
        return new class($this, $do) extends AbstractArray implements ContainerTraitInterface
        {
            use ContainerTrait;
        };
    }
    /**
     * @param callable $do
     * @return ArrayEach
     */
    public function each(callable $do)
    {
        return new class($this, _Array::each($do)) extends ArrayEach implements ContainerTraitInterface
        {
            use ContainerTrait;
        };
    }
    /**
     * @param callable $callable
     * @return ArrayMap
     */
    public function map(callable $callable)
    {
        return new class($this, _Array::map($callable)) extends ArrayMap implements ContainerTraitInterface
        {
            use ContainerTrait;
        };
    }
    /**
     * @param callable $callable
     * @return ArrayMap
     */
    public function fold(callable $callable)
    {
        return new class($this, _Array::map($callable)) extends ArrayMap implements ContainerTraitInterface
        {
            use ContainerTrait;
        };
    }
    /**
     * @param \callable[] ...$callable
     * @return ArraySort
     */
    public function sort(callable ...$callable)
    {
        return new class($this, _Array::sort(...$callable)) extends ArraySort implements ContainerTraitInterface
        {
            use ContainerTrait;
        };
    }
    /**
     * @return ArraySort
     */
    public function merge()
    {
        return new class($this, _Array::merge()) extends ArrayMerge implements ContainerTraitInterface
        {
            use ContainerTrait;
        };
    }
    /**
     * @return AbstractNode
     */
    public function sum()
    {
        return new class($this, MathNode::sum()) extends AbstractNode implements ContainerTraitInterface
        {
            use ContainerTrait;
        };
    }
    /**
     * @return ArraySort
     */
    public function values()
    {
        return new class($this, _Array::values()) extends AbstractArray implements ContainerTraitInterface
        {
            use ContainerTrait;
        };
    }
    /**
     * @param string $glue
     * @return AbstractNode
     */
    public function implode(string $glue)
    {
        return $this->then(_Array::implode($glue));
    }
    /**
     * @return IsEmptyFilter
     */
    public function isEmpty()
    {
        return new class($this, _Filter::isEmpty()) extends IsEmptyFilter implements ContainerTraitInterface
        {
            use ContainerTrait;
        };
    }
    /**
     * @return ContainsFilter
     */
    public function contains($needle, $strict = null)
    {
        return new class($this, _Filter::contains($needle, $strict)) extends ContainsFilter implements ContainerTraitInterface
        {
            use ContainerTrait;
        };
    }
}