maps the value using mapper into a different result

In case the value is null the return value still is a null result.

@param   callable  $mapper
@return  \stubbles\values\Result
559502
public function map(callable $mapper): self
    {
        if ($this->isPresent()) {
            return new self($mapper($this->value));
        }

        return self::$null;
    }
742777
public function map( $callable ) {
		$elements = array();
		$type = null;
		foreach ( $this->elements as $element ) {
			$result = call_user_func( $callable, $element );

			if ( null === $type ) {
				$type = gettype( $result );

				if ( 'object' === $type ) {
					$type = get_class( $result );
				}
			}

			$elements[] = $result;
		}

		return $this->new_from_trusted( $elements, $type ? : $this->get_type() );
	}
808195
public function call($key, $callable)
    {
        if (!is_callable($callable)) {
            throw new \InvalidArgumentException('Not a valid callable.');
        }

        if ($this->exists($key)) {
            return $this->get($key);
        }

        $args = func_get_args();
        array_shift($args);
        array_shift($args);

        $value = call_user_func_array($callable, $args);

        $this->set($key, $value);

        return $value;
    }
602248
protected function parseRoutes(Mapper $mapper)
    {
        foreach ($mapper->getClassMap() as &$mapping) {
            $mappingClass = new \ReflectionClass($mapping);

            $this->setUrlWithReflection($mapping, $mappingClass, 'resourceUrlPattern');
            $this->setUrlWithReflection($mapping, $mappingClass, 'selfUrl');
            $mappingProperty = $mappingClass->getProperty('otherUrls');
            $mappingProperty->setAccessible(true);

            $otherUrls = (array) $mappingProperty->getValue($mapping);
            if (!empty($otherUrls)) {
                foreach ($otherUrls as &$url) {
                    if (!empty($url['name'])) {
                        $url = $this->calculateRoute($url);
                    }
                }
            }
            $mappingProperty->setValue($mapping, $otherUrls);

            $this->setJsonApiRelationships($mappingClass, $mapping);
        }

        return $mapper;
    }
845380
public static Mapper mapMapper(final Map map) {
        return new Mapper() {
            public Object map(final Object a) {
                return map.get(a);
            }
        };
    }
651959
public function ksorted(?callable $comparator = null): MapInterface
    {
        $items = $comparator ?
            $this->items->ksorted($comparator) :
            $this->items->ksorted();

        return $this->duplicate($items);
    }
838307
public function map(callable $f) {
        if( $this->value !== null ) return Result::success($f($this->value));
        if( $this->error !== null ) return $this;
        throw new \LogicException("Value and error cannot both be null");
    }
284227
public static Collection map(Mapper mapper, Enumeration en) {
        return map(mapper, en, false);
    }
844154
public function getMapper($mapperClass = null, array $options = [])
    {
        $mapperClass = $mapperClass ?? $this->mapper ?? $this->serviceAlias;

        if (!array_key_exists($mapperClass, $this->mappers)) {
            $this->setMapper($mapperClass, $options);
        }

        return $this->mappers[$mapperClass];
    }
487259
public function transform(callable $transformer)
    {
        $items = $this->getItems();

        $transformed = $transformer($items instanceof Collection ? $items : new Collection($items));

        if (!($transformed instanceof Collection)) {
            throw new InvalidReturnValue;
        }

        return $transformed;
    }
445638
public static Map mapValues(Mapper mapper, Map map) {
        return mapValues(mapper, map, false);
    }
1364592
public function getMapper()
    {
        if (null === $this->mapper) {
            $class = explode('\\', get_class($this));
            $serviceKey = strtolower($this->getModuleNamespace() . '_' . end($class)) . '_mapper';
            $this->setMapper($this->getServiceLocator()->get($serviceKey));
        }
        return $this->mapper;
    }
527270
public function mapWithKeys(callable $callable)
    {
        $result = [];

        foreach ($this->attributes as $key => $attribute)
        {
            $assoc = $callable($attribute, $key);

            foreach ($assoc as $mapKey => $value)
            {
                $result[$mapKey]    =   $value;
            }
        }

        return new static($result);
    }
1360103
public function bind(string $view, $mapper)
    {
        if ($mapper instanceof \Closure) {
            return $this->set($view, $mapper($this, $view));
        }

        return $this->set($view, $mapper);
    }
29610
public function xor(Map $map): Map
    {
        return $this->merge($map)->filter(function($key) use ($map) {
            return $this->hasKey($key) ^ $map->hasKey($key);
        });
    }
983258
protected function processMapper(CommandMapper $mapper) {
        $command = $mapper->getCommand();
        try {
            $mapper->delete();
            $command->execute();
        } catch (Exception $ex) {
            $this->erroneousMappers->push($mapper);
            Yii::getLogger()->log(
                    'An error ocurred while processing command [' . get_class($command) . '].'
                    . PHP_EOL
                    . 'Exception: [' . $ex->getTraceAsString() . ']', Logger::LEVEL_ERROR, 'command'
            );
        }
    }
504370
public function respond($mapper, $data)
    {
        $arguments = [];
        // if data is instance of Paginator then get the values of the total and the page from the paginator,
        // and add them to the arguments array (total, page)
        if ($this->isPaginatorInstance($data)) {
            $arguments[0] = $data->total();
            $arguments[1] = $data->currentPage();
            $arguments[2] = $data->perPage();
        }
        // skip the first 2 arguments and save the rest to the 'arguments array':
        // > in case data is instance of Paginator then this will append all the arguments to the 'arguments array'
        // starting by the third arguments which should be the 'status'.
        // > in case data is is not instance of Paginator (means total and page and per_page are added manually as
        // arguments) then this will add all the arguments to the 'arguments array' starting by the third arguments
        // which should be the 'page'.
        foreach (array_slice(func_get_args(), 2) as $arg) {
            $arguments[count($arguments)] = $arg;
        }
        $result[] = $this->data($mapper, $data);

        return call_user_func_array([$this->response_handler, 'respond'], array_merge($result, $arguments));
    }