Download the PHP package marcegarba/funccoll without Composer

On this page you can find all versions of the php package marcegarba/funccoll. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package funccoll

PHP functional collection

Build Status Coverage Status Stable      License

This little library was inspired by Martin Fowler's collection pipeline pattern, with the intent of implementing that pattern in PHP.

The beauty in the Ruby and Clojure examples in the article contrast with PHP's clunky syntax for lambdas (closures); nevertheless, my intention is making it easy to create collection pipelines in PHP.

Installation

You can get this PHP library via a composer package in Packagist. Just add this dependency to your composer.json:

How it works

The class implements an immutable collection, backed by an array.

The class has two static factory methods, and .

The former creates a Collection object by passing a PHP array.

The latter uses a closure to generate the collection elements.

Immutability

Each transformation creates a new collection object.

The class itself implements and , so that it somehow can be used as an array; but it doesn't implement (for traversing the collection by using the foreach language construct), because that would imply having a counter and therefore making the class instances mutable.

Being immutable, the implementation of and of the interface throws a .

Obviously, the immutability has to do with the collection itself, not the state of its elements.

Extracting the array

The method extracts the original array.

If any mutation needs to be done, then it should be on this array. The mutated array, of course, can be used to create another Collection object.

Examples

Here are a couple of simple examples, using the two factory methods.

Example 1: adding odd numbers times two

A list of consecutive numbers, from 1 to 10, is used to generate the first object; successive transformations then are applied, so as to obtain the sum of the double of the first three odd numbers.

Example 2: extracting the rows from a PDO query

This example uses the result of a PDO query to generate a list of associative arrays (with a maximum of 100 elements), each of which is then used to create an entity object, based on that row contents, and the resulting array of entity objects are stored in a variable.

Summary of methods

These are the main instance methods, sorted alphabetically:

Method Meaning
count() Returns a count of all elements in the collection
drop() Creates a collection dropping the first n elements
dropWhile() Creates a collection dropping the first evaluated elements
each() Executes a closure for each element
filter() Filters a collection
findFirst() Returns the first element that matches a condition
flatten() Creates a new collection containing a flattened list
groupBy() Groups elements according to a closure
head() Returns the first element
map() Creates a new collection with elements mapped
reduce() Reduces a collection to a single value
sort() Creates a sorted collection applying a closure
tail() Creates a collection with all but the first element
take() Creates a collection with the first n elements
takeWhile() Creates a collection with the first evaluated elements
toArray() Returns copy of the Collection's inner array
values() Creates a new collection with the keys wiped

All versions of funccoll with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package marcegarba/funccoll contains the following files

Loading the files please wait ....