public function data($mapper, $data)
    {
        // we won't deal with empty data
        if (is_array($data) && empty($data)
            || (($this->isPaginatorInstance($data)) && $data->isEmpty())
            || ($data instanceof Collection && $data->isEmpty())
        ) {
            return [];
        }
        // First we check whether we've been passed an array in which case we consider the array to be ['mapper',
        // 'method'] where 'mapper' can either be the mapper class name as a string or the actual instance.
        $method = 'map';
        if (is_array($mapper) && count($mapper) == 2) {
            $instance = $mapper[0];
            $method = $mapper[1];
            $mapper = $instance;
        }
        // check whether $mapper is an actual mapper instance, otherwise
        // resolve the mapper class name into a mapper instance.
        if (!is_object($mapper)) {
            $mapper = $this->resolveMapperClassName($mapper);
        }
        // In the case of a Collection or Paginator all we need is the data as a
        // Traversable so that we iterate and map each item.
        if ($data instanceof Collection) {
            $data = $data->all();
        } elseif ($this->isPaginatorInstance($data)) {
            $data = $data->items();
        }

        // call the map function of the mapper for each data in the $data array
        return (is_array($data) && !$this->isAssocArray($data)) ?
            array_map([$mapper, $method], $data) : $mapper->$method($data);
    }