Retrieve a value that should not be created more than once

@param string $name The key we'll use to store the value once created
@param callable $callback A function to created the value if needed
@return mixed
546495
protected function get(string $name, callable $callback)
    {
        if (isset($this->cache[$name])) {
            return $this->cache[$name];
        }

        return $this->cache[$name] = call_user_func($callback, $name);
    }
319717
public static function off($name, $callback = null)
    {
        if (empty(self::$events[$name])) {
            return null;
        } elseif ($callback === null) {
            self::$events[$name] = array();
            return null;
        }

        $evts = self::$events[$name];

        foreach ($evts as $key => $value) {
            if ($value[0] === $callback) {
                unset($evts[$key]);
            }
        }

        self::$events[$name] = $evts;
        $evts = null;
    }
956006
public function map ($callback)
	{
		if(!is_callable($callback)) {
			throw new \InvalidArgumentException('Invalid (not callable) callback given');
		}

		$result = new self();

		for ($i = 0; $i < $this->count(); $i++) {
			$value = $callback($this->storage[$i]);

			if (null !== $value) {
				$result->push($value);
			}
		}

		return $result;
	}
261124
public function find($callback)
    {
        foreach ($this->value as $value) {
            if (call_user_func($callback, $value)) {
                return $value;
            }
        }
        
        return null;
    }
175805
public function unless($name, callable $callback, callable $default = null, array $context = [])
    {
        if ($this->isInactive($name, $context)) {
            return $callback($this->params($name), $context);
        } elseif ($default) {
            return $default($this->params($name), $context);
        }

        return $this;
    }
1137811
protected function notNullableValue(string $name): Closure
    {
        return function (Table $table) use ($name) {
            assert($table->hasColumn($name));
            $table->getColumn($name)->setNotnull(true);
        };
    }
1244994
public function filter($callback = null)
    {
        if ($callback !== null)
            $value = array_filter($this->value, $callback);
        else
            $value = array_filter($this->value);

        return $this->setValue($value);
    }
902347
public function unique(callable $callback) {
		$that = $this
				->group($callback)
				->map(function($group) {
					return $group[0];
				});
		return $that->resetKeys();
	}
477491
public static function createCallback(string $name, callable $callback): NormalizationFieldMappingBuilderInterface
    {
        $self = new self($name);
        $self->fieldNormalizer = new CallbackFieldNormalizer($callback);

        return $self;
    }
1249678
public function rememberForever($key, Closure $callback)
    {
        $value = $this->get($key);

        // If the item exists in the cache we will just return this immediately
        // and if not we will execute the given Closure and cache the result
        // of that forever so it is available for all subsequent requests.
        if (! is_null($value)) {
            return $value;
        }

        $this->forever($key, $value = $callback());

        return $value;
    }
818778
public function of($name, Closure $callback = null): Handler
    {
        if ($name instanceof Closure) {
            $callback = $name;
            $name = $this->getDefaultDriver();
        }

        $instance = $this->make($name);

        if ($instance instanceof Handler && ! \is_null($callback)) {
            $callback($instance);
        }

        return $instance;
    }
169347
public function detachHandler($name, callable $callback)
    {
        if (! isset($this->events[$name])) {
            return false;
        }
        $index = array_search($callback, $this->events[$name], true);
        if ($index === false) {
            return false;
        }
        unset($this->events[$name][$index]);
        return true;
    }
907375
public function make(string $name, ?Closure $callback = null) : Collection {
        return $this->collection($name, $callback);
    }
1233064
public function select($callback)
    {
        $hash = $this->create();

        foreach ($this as $key => $value) {
            if ($callback($value, $key) == true) {
                $hash[$key] = $value;
            }
        }

        return $hash;
    }
503934
protected function getCallback($callback, array $parameters)
    {
        if ($callback instanceof Closure) {
            return $this->createCallableCallback($callback, $parameters);
        } elseif (is_string($callback)) {
            return $this->createStringCallback($callback, $parameters);
        } else {
            return;
        }
    }
364709
public function table($name, $callback = null)
    {   
        if (! $callback instanceof \Closure) {
            throw InvalidArgumentPassedException::isNotClosure();
        }

        $this->setTableName($name);

        $callback($this);
        
        $tableNamePrefixed = $this->getTableNamePrefix($this->getTableName());
        $tableStructure = \substr($this->getColumnsQuery() . $this->getPrimaryKeyQuery(), 0, -2);
        $tableCharsetCollate = $this->getCharacterSetCollate();

        $this->buildCreateTableQuery($tableNamePrefixed, $tableStructure, $tableCharsetCollate);

        $this->flushColumns();
        $this->flushPrimaryKey();
    }
1062797
public static function apply($key, $callback, $default = NULL) {
		$value = self::get ( $key, $default );
		if (is_string ( $callback ) && function_exists ( $callback )) {
			$value = call_user_func ( $callback, $value );
		} elseif (is_callable ( $callback )) {
			$value = $callback ( $value );
		} else {
			return $value;
		}
		return self::set ( $key, $value );
	}