Novactive / NovaCollection

Collection implementation that wraps regular PHP arrays.
MIT License
9 stars 3 forks source link

Improvement #18

Closed anaelChardan closed 5 years ago

anaelChardan commented 7 years ago

Could be nice to have a function like this

    /**
     * Handle a result
     *
     * @param $key
     * @param callable $onSuccess
     * @param callable|null $onError
     *
     * @return mixed
     */
    public function getOrElse($key, callable $onSuccess, callable $onError = null)
    {
        if ($this->containsKey($key)) {
            return $onSuccess($key, $this->get($key));
        }

        return $onError($key);
    }
Plopix commented 7 years ago

I think I am good for that one, @nozavroni might find a better name :)