PHPackages                             nsilbernagel/accumulatephp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. nsilbernagel/accumulatephp

ActiveLibrary[Framework](/categories/framework)

nsilbernagel/accumulatephp
==========================

A PHP collections (accumulations) framework.

0.14.0(3y ago)227MITPHPPHP ~8.0 || ~8.1 || ~8.2

Since Apr 23Pushed 3y ago1 watchersCompare

[ Source](https://github.com/N-Silbernagel/AccumulatePHP)[ Packagist](https://packagist.org/packages/nsilbernagel/accumulatephp)[ RSS](/packages/nsilbernagel-accumulatephp/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (8)Versions (30)Used By (0)

[![Tests](https://github.com/N-Silbernagel/AccumulatePHP-src/actions/workflows/ci.yml/badge.svg)](https://github.com/N-Silbernagel/AccumulatePHP-src/actions/workflows/ci.yml/badge.svg)[![Latest Stable Version](https://camo.githubusercontent.com/99cd969634533758c05f23adeacbce5da5c252250a484e2729a55cfc47aa99d9/687474703a2f2f706f7365722e707567782e6f72672f6e73696c6265726e6167656c2f616363756d756c6174657068702f76)](https://packagist.org/packages/nsilbernagel/accumulatephp)[![Total Downloads](https://camo.githubusercontent.com/ad1e1da547169fb1b3dc2ee36c12726bc54b0e56c32e862470471af20afa6334/687474703a2f2f706f7365722e707567782e6f72672f6e73696c6265726e6167656c2f616363756d756c6174657068702f646f776e6c6f616473)](https://packagist.org/packages/nsilbernagel/accumulatephp)[![License](https://camo.githubusercontent.com/5cca0324ab3638015a5855608735dc5748e7f444f2349072cd9633d36f0d5269/687474703a2f2f706f7365722e707567782e6f72672f6e73696c6265726e6167656c2f616363756d756c6174657068702f6c6963656e7365)](https://packagist.org/packages/nsilbernagel/accumulatephp)[![PHP Version Require](https://camo.githubusercontent.com/26fb5c31621d2e6226232ff71d622ef1d859468d64c80b3455241b2ab9a20603/687474703a2f2f706f7365722e707567782e6f72672f6e73696c6265726e6167656c2f616363756d756c6174657068702f726571756972652f706870)](https://packagist.org/packages/nsilbernagel/accumulatephp)

Development happens at [AccumulatePHP-src](https://github.com/N-Silbernagel/AccumulatePHP-src)

AccumulatePHP
=============

[](#accumulatephp)

A PHP collections library, inspired by java collections framework.

What is this library for
------------------------

[](#what-is-this-library-for)

Using more refined datastructures allows for safer, often more efficient code than using arrays (list and assoc). TreeMap for example guarantees being searchable in O (log n). Furthermore, non-scalar keys can be used as keys in maps.

Static Analysis
---------------

[](#static-analysis)

AccumulatePHP provides first class support for static analysis through PHPStan level 9.

Installation
------------

[](#installation)

```
composer require nsilbernagel/accumulatephp
```

Usage Examples
--------------

[](#usage-examples)

ArraySeries and HashMap are the main two data structures you will be using. Here are examples of how to use them.

### ArraySeries

[](#arrayseries)

```
// create empty list
$series = ArraySeries::new();

// create list with elements 1,2 and 3
$series = ArraySeries::of(1,2,3);

// add 4
$series->add(4);

// remove 4th element
$series->remove(3);

// filter list for event number
$evenNumbers = $series->filter(fn(int $number) => $number % 2 === 0)

// map list, multiplay all elements by 2
$multiplied = $series->map(fn(int $number) => $number*2)
```

For a complete overview of ArraySeries and the other series available, please refer to the source files under src/series

### HashMap

[](#hashmap)

```
// create empty map
$map = Hashmap::new();

// create map with initial entries
$map = Hashmap::of(
    Entry::of('example', 'code'),
    Entry::of('is', 'fun'),
);

// add entry
$map->put('isnt', 'it?');

// remove entry via key
$map->remove('isnt');
```

Hashmaps can use any type keys, except for resources and arrays. Classes may implement Hashable interface to determine their hash function and definition of equality. You may refer to  to learn more about equals and hashcode and their contracts.

### Helpers

[](#helpers)

AccumulatePHP provides helper methods for creating Accumulations

```
$series = mutableSeriesOf(1,2,3);

$map = mutableMapOf(Entry::of('hello', 'world'));

$set = mutableSetOf(1,2,3);
```

Structure
---------

[](#structure)

 ```
classDiagram
    direction BT
    class Countable {

        count()
    }

    class Traversable {

    }

    class Accumulation {

      isEmpty()
      toArray()
    }
    Accumulation
