Uses a $transformer callable that takes a Collection and returns Collection on itself.

@param callable $transformer Collection => Collection
@return Collection
@throws InvalidReturnValue
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;
    }
573284
static function transform($modelOrCollection, $options = [])
    {
        $static = new static($options);

        if ($modelOrCollection instanceof Collection) {
            return $modelOrCollection->map([$static, 'transformModel'])->toArray();
        }

        return $static->transformModel($modelOrCollection);
    }
678647
public function toParameterValue($value)
    {
        foreach ($this->getTransformers() as $transformer) {
            $value = $transformer->toParameterValue($value);
        }

        return $value;
    }
366743
public function item($data, $transformer, $resourceKey = null, $meta = [])
    {
        if (!is_object($transformer) && !is_callable($transformer)) {
            $transformer = $this->di->getShared($transformer);
        }
        $resource = new Item($data, $transformer, $resourceKey);

        foreach ($meta as $metaKey => $metaValue) {
            $resource->setMetaValue($metaKey, $metaValue);
        }

        $rootScope = $this->getManager()->createData($resource);

        return $rootScope->toArray();
    }
794524
public function serializeCollection($collection, TransformerAbstract $transformer = null, $resourceKey = null)
    {
        return $this->getFractalService()
            ->collection($collection, $transformer, $resourceKey);
    }
379302
protected function makeTransformerInstance($transformerClass)
    {
        if ($transformerClass instanceof TransformerAbstract) {
            return $transformerClass;
        }

        $instance = app($transformerClass);

        if ( ! ($instance instanceof TransformerAbstract)) {
            throw new \UnexpectedValueException("{$transformerClass} is not a TransformerAbstract");
        }

        return $instance;
    }
954865
public function with($transformer)
    {
        $concrete = self::getTransformerFactory()->make($transformer);

        $this->resource->setTransformer($concrete);

        return Presentation::of($this->resource);
    }
357297
public function transformItem($resource, TransformerInterface $transformer)
    {
        $data = $transformer->execute($resource);

        $rootKey = $this->options['root_key'];
        if ($rootKey) {
            return [$rootKey => $data];
        }

        return $data;
    }
270510
public function collection($items, $transformer, $model_name = '', $meta = [])
    {
        $resource = new Collection($items, $transformer, $model_name);

        $resource->setMeta($meta);
        if ($items instanceof LengthAwarePaginator) {
            $resource->setPaginator(new IlluminatePaginatorAdapter($items));
        }

        return $this->manager->createData($resource)->toArray();
    }
428426
public function applyTransformation(ITokenTransformation $transformer, $removeNulls = true) 
    {        
        foreach($this->tokens as &$token) 
        { 
            $token = $transformer->transform($token);
        }
        //filter null tokens and re-index
        if($removeNulls) {
            $this->tokens = array_values(array_filter($this->tokens));
        }
        return $this;
    }
397104
public static <T> Transformed<T> fail(Transformer transformer) {
        return new Basic<>(transformer, null, false);
    }
317564
protected function executeResourceTransformers()
    {
        $transformer = $this->resource->getTransformer();
        $data = $this->resource->getData();

        $transformedData = $includedData = [];

        if ($this->resource instanceof Item) {
            list($transformedData, $includedData[]) = $this->fireTransformer($transformer, $data);
        } elseif ($this->resource instanceof Collection) {
            foreach ($data as $value) {
                list($transformedData[], $includedData[]) = $this->fireTransformer($transformer, $value);
            }
        } elseif ($this->resource instanceof NullResource) {
            $transformedData = null;
            $includedData = [];
        } else {
            throw new InvalidArgumentException(
                'Argument $resource should be an instance of League\Fractal\Resource\Item'
                .' or League\Fractal\Resource\Collection'
            );
        }

        return [$transformedData, $includedData];
    }
769652
protected function respondWithCollection($builder, $transformer, string $key = 'data'): JsonResponse
    {
        if (to_boolean($this->request->get('paginate', true)) === false) {
            $collection = fractal()->collection($builder)
                ->transformWith($transformer)
                ->withResourceName($key)
                ->toArray();

            $collection['meta'] = [
                'service' => env('APP_SERVICE_NAME'),
                'entity' => $transformer->getEntity()
            ];
        } else {
            $collection = $this->paginatedCollection(
                $builder,
                $transformer,
                $key,
                $this->request->get('per_page', 20)
            );
        }

        $collection['meta'] = $collection['meta'] ?? [];
        $collection['meta']['service'] = env('APP_SERVICE_NAME');
        $collection['meta']['entity'] = $transformer->getEntity();

        return $this->respondWithSuccess(
            $collection
        );
    }
298214
@SuppressWarnings("unchecked")
    public <TO> ChainedTransformer<I, TO> chain(Transformer<O, TO> transformer) {
        if (transformer != null) {
            transformers.add(transformer);
        }
        return (ChainedTransformer<I, TO>) this;
    }
824719
protected function executeResourceTransformers()
    {
        $transformer = $this->resource->getTransformer();
        $data = $this->resource->getData();

        $transformedData = $includedData = [];

        if ($this->resource instanceof FractalItem) {
            list($transformedData, $includedData[]) = $this->fireTransformer($transformer, $data);
        } elseif ($this->resource instanceof FractalCollection) {
            foreach ($data as $value) {
                list($transformedData[], $includedData[]) = $this->fireTransformer($transformer, $value);
            }
        } elseif ($this->resource instanceof FractalNullResource) {
            $transformedData = null;
            $includedData = [];
        } elseif ($this->resource instanceof NodesResourceContent) {
            $transformedData = (array) $data;
            $includedData = [];
        } else {
            throw new InvalidArgumentException(
                'Argument $resource should be an instance of League\Fractal\Resource\Item'
                .' or League\Fractal\Resource\Collection'
            );
        }

        return [$transformedData, $includedData];
    }
488978
protected <R, T extends Transformer<Transformed<R>>> Iterable<T> getTransformer(Class<T> transformerClass) {
        return Providers.getAllRankedSortedProviders(manager, transformerClass);
    }
1056359
public function transform($output, $transformer, $serializer = null)
    {
        if ($serializer !== null) {
            $this->fractal->setSerializer($this->createSerializer($serializer));
        }

        $collector = [];
        foreach ($transformer as $transform) {
            if ($transform != null) {
                $resource       = new Collection($output, $this->createTransformer($transform));
                $collection     = $this->fractal->createData($resource)->toArray();
                $transformed    = $collection['data'] ?? $collection;
                $collector      = array_map(
                    function ($item_collector, $item_transformed) {
                        if ($item_collector === null) {
                            $item_collector = [];
                        }

                        return array_merge($item_collector, $item_transformed);
                    }, $collector, $transformed
                );
            }
        }

        return $collector;
    }